From 3386f1ab28de8259b5c0a039ecf08fc60ede9b85 Mon Sep 17 00:00:00 2001 From: Kalle Stenflo Date: Mon, 15 Sep 2014 09:13:50 +0200 Subject: [PATCH] Clean up tests. --- .../com/jayway/jsonassert/JsonAssertTest.java | 7 +- .../internal/compiler/PredicatePathToken.java | 55 ++++---- .../jayway/jsonpath/old/ArraySlicingTest.java | 1 - .../com/jayway/jsonpath/old/DeepScanTest.java | 78 ----------- .../jsonpath/old/DocumentationPageTests.java | 84 ------------ .../com/jayway/jsonpath/old/FilterTest.java | 100 ++------------ .../com/jayway/jsonpath/old/HelpTest.java | 123 ------------------ .../com/jayway/jsonpath/old/IssuesTest.java | 4 +- .../jsonpath/old/JsonPathFilterTest.java | 116 ----------------- .../old/internal/ScanPathTokenTest.java | 8 ++ .../old/reader/ReadConfigurationTest.java | 41 ------ 11 files changed, 54 insertions(+), 563 deletions(-) delete mode 100644 json-path/src/test/java/com/jayway/jsonpath/old/DeepScanTest.java delete mode 100644 json-path/src/test/java/com/jayway/jsonpath/old/DocumentationPageTests.java delete mode 100644 json-path/src/test/java/com/jayway/jsonpath/old/HelpTest.java delete mode 100644 json-path/src/test/java/com/jayway/jsonpath/old/JsonPathFilterTest.java delete mode 100644 json-path/src/test/java/com/jayway/jsonpath/old/reader/ReadConfigurationTest.java diff --git a/json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java b/json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java index f33d91a8..516f9a22 100644 --- a/json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java +++ b/json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java @@ -49,6 +49,11 @@ public class JsonAssertTest { } + @Test(expected = AssertionError.class) + public void has_path() throws Exception { + + with(JSON).assertNotDefined("$.store.bicycle[?(@.color == 'red' )]"); + } @Test(expected = AssertionError.class) public void failed_error_message() throws Exception { @@ -57,7 +62,6 @@ public class JsonAssertTest { } @Test - //@Ignore //TODO: finalize behaviour public void links_document() throws Exception { with(getResourceAsStream("links.json")).assertEquals("count", 2) @@ -70,7 +74,6 @@ public class JsonAssertTest { @Test - //@Ignore //TODO: finalize behaviour public void a_document_can_be_expected_not_to_contain_a_path() throws Exception { with(JSON).assertNotDefined("$.store.bicycle.cool"); } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/PredicatePathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/PredicatePathToken.java index 4e0d4325..8090430c 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/PredicatePathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/PredicatePathToken.java @@ -22,14 +22,14 @@ public class PredicatePathToken extends PathToken { "[?,?,?,?,?]" }; - private final Collection filters; + private final Collection predicates; public PredicatePathToken(Predicate filter) { - this.filters = asList(filter); + this.predicates = asList(filter); } - public PredicatePathToken(Collection filters) { - this.filters = filters; + public PredicatePathToken(Collection predicates) { + this.predicates = predicates; } @Override @@ -58,37 +58,44 @@ public class PredicatePathToken extends PathToken { } public boolean accept(final Object obj, final Configuration configuration) { - boolean accept = true; + Predicate.PredicateContext ctx = new PredicateContextImpl(obj, configuration); - Predicate.PredicateContext ctx = new Predicate.PredicateContext() { - @Override - public Object target() { - return obj; - } - - @Override - public Configuration configuration() { - return configuration; - } - }; - - for (Predicate filter : filters) { - if (!filter.apply (ctx)) { - accept = false; - break; + for (Predicate predicate : predicates) { + if (!predicate.apply (ctx)) { + return false; } } - - return accept; + return true; } @Override public String getPathFragment() { - return FRAGMENTS[filters.size() - 1]; + return FRAGMENTS[predicates.size() - 1]; } @Override boolean isTokenDefinite() { return false; } + + + private static class PredicateContextImpl implements Predicate.PredicateContext { + private final Object obj; + private final Configuration configuration; + + private PredicateContextImpl(Object obj, Configuration configuration) { + this.obj = obj; + this.configuration = configuration; + } + + @Override + public Object target() { + return obj; + } + + @Override + public Configuration configuration() { + return configuration; + } + } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java b/json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java index 14a87080..a7276794 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java @@ -59,7 +59,6 @@ public class ArraySlicingTest { assertThat(result, Matchers.contains(1)); } - //@Test(expected = IndexOutOfBoundsException.class) @Test public void get_between_index_out_of_bounds(){ List result = JsonPath.read(JSON_ARRAY, "$[1:15]"); diff --git a/json-path/src/test/java/com/jayway/jsonpath/old/DeepScanTest.java b/json-path/src/test/java/com/jayway/jsonpath/old/DeepScanTest.java deleted file mode 100644 index cca71c6f..00000000 --- a/json-path/src/test/java/com/jayway/jsonpath/old/DeepScanTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.jayway.jsonpath.old; - -import com.jayway.jsonpath.Option; -import com.jayway.jsonpath.spi.json.JsonProvider; -import com.jayway.jsonpath.spi.json.JsonProviderFactory; - -import java.util.Collections; -import java.util.Set; - -public class DeepScanTest { - - private static final String DOCUMENT = "{\n" + - " \"store\":{\n" + - " \"book\":[\n" + - " {\n" + - " \"category\":\"reference\",\n" + - " \"author\":\"Nigel Rees\",\n" + - " \"title\":\"Sayings of the Century\",\n" + - " \"price\":8.95\n" + - " },\n" + - " {\n" + - " \"category\":\"fiction\",\n" + - " \"author\":\"Evelyn Waugh\",\n" + - " \"title\":\"Sword of Honour\",\n" + - " \"price\":12.99\n" + - " },\n" + - " {\n" + - " \"category\":\"fiction\",\n" + - " \"author\":\"J. R. R. Tolkien\",\n" + - " \"title\":\"The Lord of the Rings\",\n" + - " \"isbn\":\"0-395-19395-8\",\n" + - " \"price\":22.99\n" + - " }\n" + - " ],\n" + - " \"bicycle\":{\n" + - " \"color\":\"red\",\n" + - " \"price\":19.95\n" + - " }\n" + - " }\n" + - "}"; - - private static final JsonProvider prov = JsonProviderFactory.createProvider(); - private static final Set