Browse Source

tests of Option.ALWAYS_RETURN_LIST in case of indefinite path moved to separate test

pull/142/head
Alexey Makeyev 9 years ago
parent
commit
296d3578d6
  1. 11
      json-path/src/test/java/com/jayway/jsonpath/OptionsTest.java

11
json-path/src/test/java/com/jayway/jsonpath/OptionsTest.java

@ -48,12 +48,19 @@ public class OptionsTest extends BaseTest {
assertThat(using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(List.class); assertThat(using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(List.class);
assertThat(using(conf).parse("{\"foo\": null}").read("$.foo")).isInstanceOf(List.class); assertThat(using(conf).parse("{\"foo\": null}").read("$.foo")).isInstanceOf(List.class);
assertThat(using(conf).parse("{\"foo\": [1, 4, 8]}").read("$.foo")).asList()
.containsExactly(Arrays.asList(1, 4, 8));
}
@Test
public void an_indefinite_path_can_be_returned_as_list() {
Configuration conf = Configuration.builder().options(ALWAYS_RETURN_LIST).build();
List<Object> result = using(conf).parse("{\"bar\": {\"foo\": null}}").read("$..foo"); List<Object> result = using(conf).parse("{\"bar\": {\"foo\": null}}").read("$..foo");
assertThat(result).hasSize(1); assertThat(result).hasSize(1);
assertThat(result.get(0)).isNull(); assertThat(result.get(0)).isNull();
assertThat(using(conf).parse("{\"foo\": [1, 4, 8]}").read("$.foo")).asList()
.containsExactly(Arrays.asList(1, 4, 8));
assertThat(using(conf).parse("{\"bar\": {\"foo\": [1, 4, 8]}}").read("$..foo")).asList() assertThat(using(conf).parse("{\"bar\": {\"foo\": [1, 4, 8]}}").read("$..foo")).asList()
.containsExactly(Arrays.asList(1, 4, 8)); .containsExactly(Arrays.asList(1, 4, 8));
} }

Loading…
Cancel
Save