From 378bc9909877e6ff938bc51cceabaad842a870ab Mon Sep 17 00:00:00 2001 From: Hope Kim Date: Tue, 9 Sep 2025 15:00:56 +0900 Subject: [PATCH 1/5] Add @Nullable annotation to AbstractJsonPathAssertions.isEqualTo parameter Signed-off-by: Hope Kim Signed-off-by: khope --- .../test/web/support/AbstractJsonPathAssertions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java b/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java index 2254d39abb02..b2e842aec090 100644 --- a/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java @@ -58,7 +58,7 @@ protected AbstractJsonPathAssertions(B spec, String content, String expression, /** * Applies {@link JsonPathExpectationsHelper#assertValue(String, Object)}. */ - public B isEqualTo(Object expectedValue) { + public B isEqualTo(@Nullable Object expectedValue) { this.pathHelper.assertValue(this.content, expectedValue); return this.bodySpec; } From ce1725e29cbf259c865ad15ba5108a6e001f31be Mon Sep 17 00:00:00 2001 From: khope Date: Tue, 9 Sep 2025 15:13:42 +0900 Subject: [PATCH 2/5] Add JsonPathAssertionsTest isEqualTo with @Nullable Signed-off-by: khope --- .../servlet/client/JsonPathAssertionTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java index a63e649418d3..1a13b7ded301 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.LinkedHashMap import org.junit.jupiter.api.Test; @@ -192,6 +193,14 @@ void isArray() { .jsonPath("$.composers").isArray(); } + @Test + void isEqualToWithNull() { + client.get().uri("/music/null") + .exchange() + .expectBody() + .jsonPath("$.value").isEqualTo(null); + } + @RestController private static class MusicController { @GetMapping("/music/instruments") @@ -213,6 +222,12 @@ public MultiValueMap get() { return map; } + @GetMapping("/music/null") + public Map getNull() { + Map map = new LinkedHashMap<>(); + map.put("value", null); + return map; + } } } From 8420c51779feddd94e33969946508aa958862d3e Mon Sep 17 00:00:00 2001 From: Hope Kim Date: Tue, 9 Sep 2025 15:25:05 +0900 Subject: [PATCH 3/5] Added missing semicolon to import statement Signed-off-by: khope --- .../test/web/servlet/client/JsonPathAssertionTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java index 1a13b7ded301..8d227fe0b420 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java @@ -19,7 +19,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.LinkedHashMap +import java.util.LinkedHashMap; import org.junit.jupiter.api.Test; From f72b08bdab394cbf68b0b3191355ea348adc48a8 Mon Sep 17 00:00:00 2001 From: khope Date: Tue, 9 Sep 2025 16:02:38 +0900 Subject: [PATCH 4/5] Formmating code style JsonPathAssertionTests Signed-off-by: khope --- .../test/web/servlet/client/JsonPathAssertionTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java index 8d227fe0b420..a3ae349f5839 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java @@ -222,10 +222,13 @@ public MultiValueMap get() { return map; } + @GetMapping("/music/null") public Map getNull() { Map map = new LinkedHashMap<>(); + map.put("value", null); + return map; } } From 5e90acb3c0f4de4b31caaffc7dfe88f7259ed41a Mon Sep 17 00:00:00 2001 From: khope Date: Tue, 9 Sep 2025 16:47:55 +0900 Subject: [PATCH 5/5] Reorder imports place LinkedHashMap before List and Map Signed-off-by: khope --- .../test/web/servlet/client/JsonPathAssertionTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java index a3ae349f5839..f8fee1020e58 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/client/JsonPathAssertionTests.java @@ -17,9 +17,9 @@ package org.springframework.test.web.servlet.client; import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.LinkedHashMap; import org.junit.jupiter.api.Test;