Skip to content

Commit e0c5068

Browse files
committed
Fix incorrect assertions using json path
Closes gh-32036
1 parent faba044 commit e0c5068

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ExceptionHandlerTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -110,7 +110,7 @@ void noException() {
110110
.accept(MediaType.APPLICATION_JSON)
111111
.exchange()
112112
.expectStatus().isOk()
113-
.expectBody().jsonPath("$.name", "Yoda");
113+
.expectBody().jsonPath("$.name").isEqualTo("Yoda");
114114
}
115115

116116
@Test
@@ -123,7 +123,7 @@ void localExceptionHandlerMethod() {
123123
.accept(MediaType.APPLICATION_JSON)
124124
.exchange()
125125
.expectStatus().isOk()
126-
.expectBody().jsonPath("$.error", "local - IllegalArgumentException");
126+
.expectBody().jsonPath("$.error").isEqualTo("local - IllegalArgumentException");
127127
}
128128

129129
@Test
@@ -136,7 +136,7 @@ void globalExceptionHandlerMethod() {
136136
.accept(MediaType.APPLICATION_JSON)
137137
.exchange()
138138
.expectStatus().isOk()
139-
.expectBody().jsonPath("$.error", "global - IllegalArgumentException");
139+
.expectBody().jsonPath("$.error").isEqualTo("global - IllegalStateException");
140140
}
141141

142142
@Test
@@ -149,7 +149,7 @@ void globalRestPersonControllerExceptionHandlerTakesPrecedenceOverGlobalExceptio
149149
.accept(MediaType.APPLICATION_JSON)
150150
.exchange()
151151
.expectStatus().isOk()
152-
.expectBody().jsonPath("$.error", "globalPersonController - IllegalStateException");
152+
.expectBody().jsonPath("$.error").isEqualTo("globalPersonController - IllegalStateException");
153153
}
154154

155155
@Test
@@ -162,7 +162,7 @@ void noHandlerFound() {
162162
.accept(MediaType.APPLICATION_JSON)
163163
.exchange()
164164
.expectStatus().isOk()
165-
.expectBody().jsonPath("$.error", "global - NoHandlerFoundException");
165+
.expectBody().jsonPath("$.error").isEqualTo("global - NoHandlerFoundException");
166166
}
167167
}
168168

spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RequestParameterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void queryParameter() {
4545
.exchange()
4646
.expectStatus().isOk()
4747
.expectHeader().contentType(MediaType.APPLICATION_JSON)
48-
.expectBody().jsonPath("$.name", "George");
48+
.expectBody().jsonPath("$.name").isEqualTo("George");
4949
}
5050

5151

spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ViewResolutionTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,7 +85,7 @@ void jsonOnly() {
8585
.exchange()
8686
.expectStatus().isOk()
8787
.expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
88-
.expectBody().jsonPath("$.person.name", "Corea");
88+
.expectBody().jsonPath("$.person.name").isEqualTo("Corea");
8989
}
9090

9191
@Test
@@ -143,7 +143,7 @@ void contentNegotiation() throws Exception {
143143
.exchange()
144144
.expectStatus().isOk()
145145
.expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
146-
.expectBody().jsonPath("$.person.name", "Corea");
146+
.expectBody().jsonPath("$.person.name").isEqualTo("Corea");
147147

148148
testClient.get().uri("/person/Corea")
149149
.accept(MediaType.APPLICATION_XML)

0 commit comments

Comments
 (0)