From 07390fcb16ea3c46b90048642fb9b25767e82a7d Mon Sep 17 00:00:00 2001 From: Kalle Stenflo Date: Wed, 11 Nov 2015 23:44:43 +0100 Subject: [PATCH] Added tests for EMPTY operator. --- .../java/com/jayway/jsonpath/FilterTest.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 d1aafce4..da6b87a2 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java @@ -370,7 +370,7 @@ public class FilterTest extends BaseTest { //---------------------------------------------------------------------------- // - // EMPTY + // NOT EMPTY // //---------------------------------------------------------------------------- @Test @@ -384,6 +384,29 @@ public class FilterTest extends BaseTest { assertThat(filter(where("null-key").notEmpty()).apply(createPredicateContext(json))).isEqualTo(false); } + //---------------------------------------------------------------------------- + // + // EMPTY + // + //---------------------------------------------------------------------------- + @Test + public void empty_evals() { + assertThat(filter(where("string-key").empty(false)).apply(createPredicateContext(json))).isEqualTo(true); + assertThat(filter(where("string-key").empty(true)).apply(createPredicateContext(json))).isEqualTo(false); + + assertThat(filter(where("string-key-empty").empty(true)).apply(createPredicateContext(json))).isEqualTo(true); + assertThat(filter(where("string-key-empty").empty(false)).apply(createPredicateContext(json))).isEqualTo(false); + + assertThat(filter(where("int-arr").empty(false)).apply(createPredicateContext(json))).isEqualTo(true); + assertThat(filter(where("int-arr").empty(true)).apply(createPredicateContext(json))).isEqualTo(false); + + assertThat(filter(where("arr-empty").empty(true)).apply(createPredicateContext(json))).isEqualTo(true); + assertThat(filter(where("arr-empty").empty(false)).apply(createPredicateContext(json))).isEqualTo(false); + + assertThat(filter(where("null-key").empty(true)).apply(createPredicateContext(json))).isEqualTo(false); + assertThat(filter(where("null-key").empty(false)).apply(createPredicateContext(json))).isEqualTo(false); + } + //---------------------------------------------------------------------------- //