Fix error message for type mismatch in jsonPath().value()
Prior to this commit, if a value existed at the specified JSON path but had an incompatible type, the AssertionError thrown contained a message stating that the value did not exist (i.e., "No Value at JSON Path"), which was not only misleading but also technically incorrect. This commit fixes the error message for such use cases. For example, the AssertionError thrown in such use cases now resembles the following. At JSON path "$.name", value <Lisa> of type <java.lang.String> cannot be converted to type <byte[]> Closes gh-25480
This commit is contained in:
@@ -64,9 +64,17 @@ public class JsonPathResultMatchersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWithMismatch() throws Exception {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
|
||||
new JsonPathResultMatchers("$.str").value("bogus").match(stubMvcResult));
|
||||
public void valueWithValueMismatch() throws Exception {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> new JsonPathResultMatchers("$.str").value("bogus").match(stubMvcResult))
|
||||
.withMessage("JSON path \"$.str\" expected:<bogus> but was:<foo>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWithTypeMismatch() throws Exception {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> new JsonPathResultMatchers("$.str").value("bogus".getBytes()).match(stubMvcResult))
|
||||
.withMessage("At JSON path \"$.str\", value <foo> of type <java.lang.String> cannot be converted to type <byte[]>");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user