Search in sources :

Example 1 with TextNode

use of io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.TextNode in project cucumber-jvm by cucumber.

the class AComparableMessage method aComparableValue.

@SuppressWarnings("unchecked")
private static Matcher<?> aComparableValue(Object value, int depth) {
    if (value instanceof ObjectNode) {
        JsonNode message = (JsonNode) value;
        return new AComparableMessage(message, depth);
    }
    if (value instanceof ArrayNode) {
        ArrayNode values = (ArrayNode) value;
        Spliterator<JsonNode> spliterator = spliteratorUnknownSize(values.iterator(), 0);
        List<Matcher<? super Object>> allComparableValues = stream(spliterator, false).map(o -> aComparableValue(o, depth)).map(o -> (Matcher<? super Object>) o).collect(Collectors.toList());
        return contains(allComparableValues);
    }
    if (value instanceof TextNode || value instanceof NumericNode || value instanceof BooleanNode) {
        return CoreMatchers.is(value);
    }
    throw new IllegalArgumentException("Unsupported type " + value.getClass() + ": " + value);
}
Also used : Spliterators.spliteratorUnknownSize(java.util.Spliterators.spliteratorUnknownSize) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers(org.hamcrest.CoreMatchers) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) CoreMatchers.isA(org.hamcrest.CoreMatchers.isA) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JsonNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher) LinkedHashMap(java.util.LinkedHashMap) NumericNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.NumericNode) Map(java.util.Map) TextNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.TextNode) IsMapContaining.hasEntry(org.hamcrest.collection.IsMapContaining.hasEntry) Description(org.hamcrest.Description) IsMapContaining.hasKey(org.hamcrest.collection.IsMapContaining.hasKey) ObjectNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.ObjectNode) IsIterableContainingInRelativeOrder.containsInRelativeOrder(org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder) ArrayNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.ArrayNode) BooleanNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.BooleanNode) Collectors(java.util.stream.Collectors) List(java.util.List) StreamSupport.stream(java.util.stream.StreamSupport.stream) Matcher(org.hamcrest.Matcher) Spliterator(java.util.Spliterator) ObjectNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.ObjectNode) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher) Matcher(org.hamcrest.Matcher) JsonNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode) TextNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.TextNode) NumericNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.NumericNode) BooleanNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.BooleanNode) ArrayNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

JsonNode (io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.ArrayNode)1 BooleanNode (io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.BooleanNode)1 NumericNode (io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.NumericNode)1 ObjectNode (io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (io.cucumber.messages.internal.com.fasterxml.jackson.databind.node.TextNode)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Spliterator (java.util.Spliterator)1 Spliterators.spliteratorUnknownSize (java.util.Spliterators.spliteratorUnknownSize)1 Collectors (java.util.stream.Collectors)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 CoreMatchers (org.hamcrest.CoreMatchers)1 CoreMatchers.anyOf (org.hamcrest.CoreMatchers.anyOf)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 CoreMatchers.isA (org.hamcrest.CoreMatchers.isA)1 CoreMatchers.not (org.hamcrest.CoreMatchers.not)1 Description (org.hamcrest.Description)1