Browse Source

Merge pull request #263 from helsing/issue_254_assert_on_read_context

Allow ReadContext to be matched by isJson()/hasJsonPath() matchers - issue #254
pull/283/head
kallestenflo 8 years ago committed by GitHub
parent
commit
8f788bc3a2
  1. 2
      json-path-assert/src/main/java/com/jayway/jsonpath/matchers/IsJson.java
  2. 11
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/JsonPathMatchersTest.java

2
json-path-assert/src/main/java/com/jayway/jsonpath/matchers/IsJson.java

@ -58,6 +58,8 @@ public class IsJson<T> extends TypeSafeMatcher<T> {
return JsonPath.parse((String) object);
} else if (object instanceof File) {
return JsonPath.parse((File) object);
} else if (object instanceof ReadContext) {
return (ReadContext) object;
} else {
return JsonPath.parse(object);
}

11
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/JsonPathMatchersTest.java

@ -1,6 +1,8 @@
package com.jayway.jsonpath.matchers;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.ReadContext;
import com.jayway.jsonpath.matchers.helpers.StrictParsingConfiguration;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -209,4 +211,13 @@ public class JsonPathMatchersTest {
Object json = Configuration.defaultConfiguration().jsonProvider().parse(BOOKS_JSON);
assertThat(json, hasJsonPath("$.store.name", equalTo("Little Shop")));
}
@Test
public void shouldMatchJsonPathOnReadContext() {
String test = "{\"foo\":\"bar\"}";
ReadContext context = JsonPath.parse(test);
assertThat(context, hasJsonPath("$.foo"));
assertThat(context, hasJsonPath("$.foo", equalTo("bar")));
assertThat(context, hasNoJsonPath("$.zoo"));
}
}

Loading…
Cancel
Save