diff --git a/json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java b/json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java index a073d9b1..948ca75f 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java @@ -1,5 +1,6 @@ package com.jayway.jsonpath; +import java.util.Collections; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -142,6 +143,15 @@ public class FilterParseTest { assertThat(filter).isEqualTo(parsed); } + @Test + public void a_subsetof_filter_can_be_serialized() { + + String filter = filter(where("a").subsetof(Collections.emptyList())).toString(); + String parsed = parse("[?(@['a'] SUBSETOF [])]").toString(); + + assertThat(filter).isEqualTo(parsed); + } + @Test public void a_exists_filter_can_be_serialized() { diff --git a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java index a9c02e76..e786ae83 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java @@ -1,5 +1,7 @@ package com.jayway.jsonpath; +import java.util.ArrayList; +import org.assertj.core.util.Lists; import org.junit.Test; import java.util.HashMap; @@ -358,6 +360,24 @@ public class FilterTest extends BaseTest { assertThat(filter(where("null-key").size(6)).apply(createPredicateContext(json))).isEqualTo(false); } + //---------------------------------------------------------------------------- + // + // SUBSETOF + // + //---------------------------------------------------------------------------- + @Test + public void array_subsetof_evals() { + // list is a superset + List list = Lists.newArrayList("a", "b", "c", "d", "e", "f", "g"); + assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(true); + // list is exactly the same set (but in a different order) + list = Lists.newArrayList("e", "d", "b", "c", "a"); + assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(true); + // list is missing one element + list = Lists.newArrayList("a", "b", "c", "d"); + assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(false); + } + //---------------------------------------------------------------------------- // // EXISTS