From 9e8c64011d547dc167212c5552b6b2116532d707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 9 Sep 2025 11:14:21 +0200 Subject: [PATCH] Make JsonPathAssertions#isEqualTo parameter nullable Closes gh-35445 --- .../test/web/reactive/server/JsonPathAssertions.java | 2 +- .../test/util/JsonPathExpectationsHelperTests.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java index acea1d3ae61..f758846b037 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java @@ -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; } diff --git a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java index 21cdc4a1d4e..964da8655cc 100644 --- a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java @@ -57,7 +57,8 @@ class JsonPathExpectationsHelperTests { 'whitespace': ' ', 'emptyString': '', 'emptyArray': [], - 'emptyMap': {} + 'emptyMap': {}, + 'nullValue': null }"""; private static final String SIMPSONS = """ @@ -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);