11package com .baeldung .jsonpath .introduction ;
22
3- import static org . junit . Assert . assertEquals ;
4- import static org . junit . Assert . assertThat ;
5- import static org . hamcrest . CoreMatchers . containsString ;
6- import static org . hamcrest . CoreMatchers . not ;
7-
3+ import com . jayway . jsonpath . Criteria ;
4+ import com . jayway . jsonpath . DocumentContext ;
5+ import com . jayway . jsonpath . Filter ;
6+ import com . jayway . jsonpath . JsonPath ;
7+ import com . jayway . jsonpath . Predicate ;
88import org .junit .Test ;
99
1010import java .io .InputStream ;
1111import java .util .List ;
1212import java .util .Map ;
1313import java .util .Scanner ;
1414
15- import com .jayway .jsonpath .Criteria ;
16- import com .jayway .jsonpath .DocumentContext ;
17- import com .jayway .jsonpath .Filter ;
18- import com .jayway .jsonpath .JsonPath ;
19- import com .jayway .jsonpath .Predicate ;
15+ import static org .hamcrest .CoreMatchers .containsString ;
16+ import static org .hamcrest .CoreMatchers .not ;
17+ import static org .junit .Assert .assertEquals ;
18+ import static org .junit .Assert .assertThat ;
2019
2120public class OperationIntegrationTest {
22- InputStream jsonInputStream = this .getClass ().getClassLoader ().getResourceAsStream ("intro_api.json" );
23- String jsonDataSourceString = new Scanner (jsonInputStream , "UTF-8" ).useDelimiter ("\\ Z" ).next ();
21+ private InputStream jsonInputStream = this .getClass ().getClassLoader ().getResourceAsStream ("intro_api.json" );
22+ private String jsonDataSourceString = new Scanner (jsonInputStream , "UTF-8" ).useDelimiter ("\\ Z" ).next ();
2423
2524 @ Test
2625 public void givenJsonPathWithoutPredicates_whenReading_thenCorrect () {
@@ -46,12 +45,7 @@ public void givenJsonPathWithFilterPredicate_whenReading_thenCorrect() {
4645
4746 @ Test
4847 public void givenJsonPathWithCustomizedPredicate_whenReading_thenCorrect () {
49- Predicate expensivePredicate = new Predicate () {
50- public boolean apply (PredicateContext context ) {
51- String value = context .item (Map .class ).get ("price" ).toString ();
52- return Float .valueOf (value ) > 20.00 ;
53- }
54- };
48+ Predicate expensivePredicate = context -> Float .valueOf (context .item (Map .class ).get ("price" ).toString ()) > 20.00 ;
5549 List <Map <String , Object >> expensive = JsonPath .parse (jsonDataSourceString ).read ("$['book'][?]" , expensivePredicate );
5650 predicateUsageAssertionHelper (expensive );
5751 }
0 commit comments