44import org .junit .jupiter .api .BeforeAll ;
55import org .junit .jupiter .api .Test ;
66
7- import java .util .List ;
87import java .util .logging .Logger ;
98
109import static org .assertj .core .api .Assertions .assertThat ;
1110
12- /// Tests for JsonPath based on examples from https://goessner.net/articles/JsonPath/
11+ /// Tests for JsonPath based on examples from [...]( https://goessner.net/articles/JsonPath/)
1312/// This test class uses the sample JSON document from the article.
1413class JsonPathGoessnerTest extends JsonPathLoggingConfig {
1514
@@ -36,14 +35,14 @@ class JsonPathGoessnerTest extends JsonPathLoggingConfig {
3635 "category": "fiction",
3736 "author": "Herman Melville",
3837 "title": "Moby Dick",
39- "isbn ": "0-553-21311-3",
38+ "ISBN ": "0-553-21311-3",
4039 "price": 8.99
4140 },
4241 {
4342 "category": "fiction",
4443 "author": "J. R. R. Tolkien",
4544 "title": "The Lord of the Rings",
46- "isbn ": "0-395-19395-8",
45+ "ISBN ": "0-395-19395-8",
4746 "price": 22.99
4847 }
4948 ],
@@ -89,7 +88,7 @@ void testNestedProperty() {
8988 assertThat (results .getFirst ()).isInstanceOf (JsonObject .class );
9089 final var bicycle = (JsonObject ) results .getFirst ();
9190 assertThat (bicycle .members ().get ("color" )).isInstanceOf (JsonString .class );
92- assertThat ((( JsonString ) bicycle .members ().get ("color" ) ).string ()).isEqualTo ("red" );
91+ assertThat (bicycle .members ().get ("color" ).string ()).isEqualTo ("red" );
9392 }
9493
9594 // ========== Goessner Article Examples ==========
@@ -100,7 +99,7 @@ void testAuthorsOfAllBooks() {
10099 final var results = JsonPath .query ("$.store.book[*].author" , storeJson );
101100 assertThat (results ).hasSize (4 );
102101 final var authors = results .stream ()
103- .map (v -> (( JsonString ) v ). string () )
102+ .map (JsonValue :: string )
104103 .toList ();
105104 assertThat (authors ).containsExactly (
106105 "Nigel Rees" ,
@@ -116,7 +115,7 @@ void testAllAuthorsRecursive() {
116115 final var results = JsonPath .query ("$..author" , storeJson );
117116 assertThat (results ).hasSize (4 );
118117 final var authors = results .stream ()
119- .map (v -> (( JsonString ) v ). string () )
118+ .map (JsonValue :: string )
120119 .toList ();
121120 assertThat (authors ).containsExactlyInAnyOrder (
122121 "Nigel Rees" ,
@@ -139,7 +138,7 @@ void testAllPricesInStore() {
139138 final var results = JsonPath .query ("$.store..price" , storeJson );
140139 assertThat (results ).hasSize (5 ); // 4 book prices + 1 bicycle price
141140 final var prices = results .stream ()
142- .map (v -> (( JsonNumber ) v ). toDouble () )
141+ .map (JsonValue :: toDouble )
143142 .toList ();
144143 assertThat (prices ).containsExactlyInAnyOrder (8.95 , 12.99 , 8.99 , 22.99 , 19.95 );
145144 }
@@ -150,7 +149,7 @@ void testThirdBook() {
150149 final var results = JsonPath .query ("$..book[2]" , storeJson );
151150 assertThat (results ).hasSize (1 );
152151 final var book = (JsonObject ) results .getFirst ();
153- assertThat ((( JsonString ) book .members ().get ("title" ) ).string ()).isEqualTo ("Moby Dick" );
152+ assertThat (book .members ().get ("title" ).string ()).isEqualTo ("Moby Dick" );
154153 }
155154
156155 @ Test
@@ -159,7 +158,7 @@ void testLastBookScriptExpression() {
159158 final var results = JsonPath .query ("$..book[(@.length-1)]" , storeJson );
160159 assertThat (results ).hasSize (1 );
161160 final var book = (JsonObject ) results .getFirst ();
162- assertThat ((( JsonString ) book .members ().get ("title" ) ).string ()).isEqualTo ("The Lord of the Rings" );
161+ assertThat (book .members ().get ("title" ).string ()).isEqualTo ("The Lord of the Rings" );
163162 }
164163
165164 @ Test
@@ -168,7 +167,7 @@ void testLastBookSlice() {
168167 final var results = JsonPath .query ("$..book[-1:]" , storeJson );
169168 assertThat (results ).hasSize (1 );
170169 final var book = (JsonObject ) results .getFirst ();
171- assertThat ((( JsonString ) book .members ().get ("title" ) ).string ()).isEqualTo ("The Lord of the Rings" );
170+ assertThat (book .members ().get ("title" ).string ()).isEqualTo ("The Lord of the Rings" );
172171 }
173172
174173 @ Test
@@ -177,7 +176,7 @@ void testFirstTwoBooksUnion() {
177176 final var results = JsonPath .query ("$..book[0,1]" , storeJson );
178177 assertThat (results ).hasSize (2 );
179178 final var titles = results .stream ()
180- .map (v -> (( JsonString ) (( JsonObject ) v ) .members ().get ("title" ) ).string ())
179+ .map (v -> v .members ().get ("title" ).string ())
181180 .toList ();
182181 assertThat (titles ).containsExactly ("Sayings of the Century" , "Sword of Honour" );
183182 }
@@ -188,7 +187,7 @@ void testFirstTwoBooksSlice() {
188187 final var results = JsonPath .query ("$..book[:2]" , storeJson );
189188 assertThat (results ).hasSize (2 );
190189 final var titles = results .stream ()
191- .map (v -> (( JsonString ) (( JsonObject ) v ) .members ().get ("title" ) ).string ())
190+ .map (v -> v .members ().get ("title" ).string ())
192191 .toList ();
193192 assertThat (titles ).containsExactly ("Sayings of the Century" , "Sword of Honour" );
194193 }
@@ -199,7 +198,7 @@ void testBooksWithIsbn() {
199198 final var results = JsonPath .query ("$..book[?(@.isbn)]" , storeJson );
200199 assertThat (results ).hasSize (2 );
201200 final var titles = results .stream ()
202- .map (v -> (( JsonString ) (( JsonObject ) v ) .members ().get ("title" ) ).string ())
201+ .map (v -> v .members ().get ("title" ).string ())
203202 .toList ();
204203 assertThat (titles ).containsExactlyInAnyOrder ("Moby Dick" , "The Lord of the Rings" );
205204 }
@@ -210,7 +209,7 @@ void testBooksCheaperThan10() {
210209 final var results = JsonPath .query ("$..book[?(@.price<10)]" , storeJson );
211210 assertThat (results ).hasSize (2 );
212211 final var titles = results .stream ()
213- .map (v -> (( JsonString ) (( JsonObject ) v ) .members ().get ("title" ) ).string ())
212+ .map (v -> v .members ().get ("title" ).string ())
214213 .toList ();
215214 assertThat (titles ).containsExactlyInAnyOrder ("Sayings of the Century" , "Moby Dick" );
216215 }
@@ -232,7 +231,7 @@ void testArrayIndexFirst() {
232231 final var results = JsonPath .query ("$.store.book[0]" , storeJson );
233232 assertThat (results ).hasSize (1 );
234233 final var book = (JsonObject ) results .getFirst ();
235- assertThat ((( JsonString ) book .members ().get ("author" ) ).string ()).isEqualTo ("Nigel Rees" );
234+ assertThat (book .members ().get ("author" ).string ()).isEqualTo ("Nigel Rees" );
236235 }
237236
238237 @ Test
@@ -241,7 +240,7 @@ void testArrayIndexNegative() {
241240 final var results = JsonPath .query ("$.store.book[-1]" , storeJson );
242241 assertThat (results ).hasSize (1 );
243242 final var book = (JsonObject ) results .getFirst ();
244- assertThat ((( JsonString ) book .members ().get ("author" ) ).string ()).isEqualTo ("J. R. R. Tolkien" );
243+ assertThat (book .members ().get ("author" ).string ()).isEqualTo ("J. R. R. Tolkien" );
245244 }
246245
247246 @ Test
@@ -250,7 +249,7 @@ void testBracketNotationProperty() {
250249 final var results = JsonPath .query ("$['store']['book'][0]" , storeJson );
251250 assertThat (results ).hasSize (1 );
252251 final var book = (JsonObject ) results .getFirst ();
253- assertThat ((( JsonString ) book .members ().get ("author" ) ).string ()).isEqualTo ("Nigel Rees" );
252+ assertThat (book .members ().get ("author" ).string ()).isEqualTo ("Nigel Rees" );
254253 }
255254
256255 @ Test
@@ -280,7 +279,7 @@ void testSliceWithStep() {
280279 final var results = JsonPath .query ("$.store.book[0:4:2]" , storeJson );
281280 assertThat (results ).hasSize (2 ); // books at index 0 and 2
282281 final var titles = results .stream ()
283- .map (v -> (( JsonString ) (( JsonObject ) v ) .members ().get ("title" ) ).string ())
282+ .map (v -> v .members ().get ("title" ).string ())
284283 .toList ();
285284 assertThat (titles ).containsExactly ("Sayings of the Century" , "Moby Dick" );
286285 }
@@ -290,7 +289,7 @@ void testDeepNestedAccess() {
290289 LOG .info (() -> "TEST: testDeepNestedAccess - $.store.book[0].title" );
291290 final var results = JsonPath .query ("$.store.book[0].title" , storeJson );
292291 assertThat (results ).hasSize (1 );
293- assertThat ((( JsonString ) results .getFirst () ).string ()).isEqualTo ("Sayings of the Century" );
292+ assertThat (results .getFirst ().string ()).isEqualTo ("Sayings of the Century" );
294293 }
295294
296295 @ Test
@@ -314,7 +313,7 @@ void testFilterGreaterThan() {
314313 final var results = JsonPath .query ("$..book[?(@.price>20)]" , storeJson );
315314 assertThat (results ).hasSize (1 );
316315 final var book = (JsonObject ) results .getFirst ();
317- assertThat ((( JsonString ) book .members ().get ("title" ) ).string ()).isEqualTo ("The Lord of the Rings" );
316+ assertThat (book .members ().get ("title" ).string ()).isEqualTo ("The Lord of the Rings" );
318317 }
319318
320319 @ Test
@@ -351,7 +350,7 @@ void testFluentApiReusable() {
351350 """ );
352351 final var simpleResults = compiledPath .select (simpleDoc );
353352 assertThat (simpleResults ).hasSize (1 );
354- assertThat ((( JsonNumber ) simpleResults .getFirst () ).toDouble ()).isEqualTo (99.99 );
353+ assertThat (simpleResults .getFirst ().toDouble ()).isEqualTo (99.99 );
355354 }
356355
357356 @ Test
0 commit comments