From c05c4364bc1675af98b3ec7456c935576a8ba97d Mon Sep 17 00:00:00 2001 From: Jack Singleton Date: Wed, 10 Jul 2013 12:17:23 -0700 Subject: [PATCH] Added tests for query for null field and query for property on array --- .../com/jayway/jsonpath/JsonModelTest.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java index f811880a..b9d83dee 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java @@ -9,9 +9,7 @@ import java.util.HashMap; import java.util.Map; import static java.util.Arrays.asList; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; +import static junit.framework.Assert.*; /** * Created by IntelliJ IDEA. @@ -106,6 +104,24 @@ public class JsonModelTest { JsonModel.model(DOCUMENT).get("store.invalid"); } + @Test + public void query_for_null_property_returns_null() { + String documentWithNull = + "{ \"store\": {\n" + + " \"book\": { \n" + + " \"color\": null\n" + + " }\n" + + " }\n" + + "}"; + + Object color = JsonModel.model(documentWithNull).get("store.book.color"); + + assertNull(color); + } + @Test(expected = InvalidPathException.class) + public void query_for_property_on_array_throws() throws Exception { + JsonModel.model(DOCUMENT).get("store.book.color"); + } }