From f25ec6c0cdf70fb8bbc46e1514d4ca55809e9a5c Mon Sep 17 00:00:00 2001 From: gauravgupta Date: Tue, 13 Oct 2015 19:22:33 -0400 Subject: [PATCH] fixed the cache key and the unit test (use the same key when fetching and looking up cache) #94 --- .../main/java/com/jayway/jsonpath/internal/JsonReader.java | 2 +- .../java/com/jayway/jsonpath/internal/JsonReaderTest.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java index 9e7b9cc2..c896ed9b 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java @@ -147,7 +147,7 @@ public class JsonReader implements ParseContext, DocumentContext { return read(jsonPath); }else { jsonPath = compile(path, filters); - cache.put(path, jsonPath); + cache.put(cacheKey, jsonPath); return read(jsonPath); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java index efecffef..7cac7629 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java @@ -9,6 +9,7 @@ import org.junit.Test; import com.jayway.jsonpath.BaseTest; import com.jayway.jsonpath.Criteria; +import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.Filter; import com.jayway.jsonpath.JsonPath; @@ -19,9 +20,11 @@ public class JsonReaderTest extends BaseTest { Filter feq = Filter.filter(Criteria.where("category").eq("reference")); Filter fne = Filter.filter(Criteria.where("category").ne("reference")); + + DocumentContext JsonDoc = JsonPath.parse(JSON_DOCUMENT); - List eq = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?].category", feq); - List ne = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?].category", fne); + List eq = JsonDoc.read("$.store.book[?].category", feq); + List ne = JsonDoc.read("$.store.book[?].category", fne); Assertions.assertThat(eq).contains("reference"); Assertions.assertThat(ne).doesNotContain("reference");