Browse Source

Make JsonPathAssertions#isEqualTo parameter nullable

Closes gh-35445
pull/35587/head
Sébastien Deleuze 3 months ago
parent
commit
9e8c64011d
  1. 2
      spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java
  2. 8
      spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java

2
spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java

@ -56,7 +56,7 @@ public class JsonPathAssertions { @@ -56,7 +56,7 @@ public class JsonPathAssertions {
/**
* Applies {@link JsonPathExpectationsHelper#assertValue(String, Object)}.
*/
public WebTestClient.BodyContentSpec isEqualTo(Object expectedValue) {
public WebTestClient.BodyContentSpec isEqualTo(@Nullable Object expectedValue) {
this.pathHelper.assertValue(this.content, expectedValue);
return this.bodySpec;
}

8
spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java

@ -57,7 +57,8 @@ class JsonPathExpectationsHelperTests { @@ -57,7 +57,8 @@ class JsonPathExpectationsHelperTests {
'whitespace': ' ',
'emptyString': '',
'emptyArray': [],
'emptyMap': {}
'emptyMap': {},
'nullValue': null
}""";
private static final String SIMPSONS = """
@ -249,6 +250,11 @@ class JsonPathExpectationsHelperTests { @@ -249,6 +250,11 @@ class JsonPathExpectationsHelperTests {
new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, 5);
}
@Test
void assertNullValue() {
new JsonPathExpectationsHelper("$.nullValue").assertValue(CONTENT, (Object) null);
}
@Test // SPR-14498
void assertValueWithNumberConversion() {
new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, 5.0);

Loading…
Cancel
Save