Skip to content

Commit 3b2f6e7

Browse files
committed
Make assertions based on Annotation#toString() lenient
The behavior for the toString() implementation for annotations changed in JDK 19, per my request to the JDK team (see link below). Specifically, since JDK 19, the toString() implementation for annotation proxies created by the JDK started using canonical names instead of binary names for types. See https://bugs.openjdk.org/browse/JDK-8281462
1 parent 484aee0 commit 3b2f6e7

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

Diff for: spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ void multipleAnnotationsAtClassLevel() {
220220
.isThrownBy(() -> this.proxyFactory.createClient(serviceInterface))
221221
.withMessageContainingAll(
222222
"Multiple @HttpExchange annotations found on " + serviceInterface,
223-
"@" + HttpExchange.class.getName(),
224-
"@" + ExtraHttpExchange.class.getName()
223+
HttpExchange.class.getSimpleName(),
224+
ExtraHttpExchange.class.getSimpleName()
225225
);
226226
}
227227

@@ -234,8 +234,8 @@ void multipleAnnotationsAtMethodLevel() throws NoSuchMethodException {
234234
.isThrownBy(() -> this.proxyFactory.createClient(serviceInterface))
235235
.withMessageContainingAll(
236236
"Multiple @HttpExchange annotations found on method " + method,
237-
"@" + PostExchange.class.getName(),
238-
"@" + PutExchange.class.getName()
237+
PostExchange.class.getSimpleName(),
238+
PutExchange.class.getSimpleName()
239239
);
240240
}
241241

Diff for: spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMappingTests.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ void httpExchangeWithMultipleAnnotationsAtClassLevel() {
163163
.isThrownBy(() -> this.handlerMapping.getMappingForMethod(method, controllerClass))
164164
.withMessageContainingAll(
165165
"Multiple @HttpExchange annotations found on " + controllerClass,
166-
"@" + HttpExchange.class.getName(),
167-
"@" + ExtraHttpExchange.class.getName()
166+
HttpExchange.class.getSimpleName(),
167+
ExtraHttpExchange.class.getSimpleName()
168168
);
169169
}
170170

@@ -179,8 +179,8 @@ void httpExchangeWithMultipleAnnotationsAtMethodLevel() {
179179
.isThrownBy(() -> this.handlerMapping.getMappingForMethod(method, controllerClass))
180180
.withMessageContainingAll(
181181
"Multiple @HttpExchange annotations found on " + method,
182-
"@" + PostExchange.class.getName(),
183-
"@" + PutExchange.class.getName()
182+
PostExchange.class.getSimpleName(),
183+
PutExchange.class.getSimpleName()
184184
);
185185
}
186186

@@ -196,8 +196,8 @@ void httpExchangeWithMixedAnnotationsAtClassLevel() {
196196
.withMessageContainingAll(
197197
controllerClass.getName(),
198198
"is annotated with @RequestMapping and @HttpExchange annotations, but only one is allowed:",
199-
"@" + RequestMapping.class.getName(),
200-
"@" + HttpExchange.class.getName()
199+
RequestMapping.class.getSimpleName(),
200+
HttpExchange.class.getSimpleName()
201201
);
202202
}
203203

@@ -213,8 +213,8 @@ void httpExchangeWithMixedAnnotationsAtMethodLevel() {
213213
.withMessageContainingAll(
214214
method.toString(),
215215
"is annotated with @RequestMapping and @HttpExchange annotations, but only one is allowed:",
216-
"@" + PostMapping.class.getName(),
217-
"@" + PostExchange.class.getName()
216+
PostMapping.class.getSimpleName(),
217+
PostExchange.class.getSimpleName()
218218
);
219219
}
220220

Diff for: spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ void httpExchangeWithMultipleAnnotationsAtClassLevel() throws NoSuchMethodExcept
289289
.isThrownBy(() -> mapping.getMappingForMethod(method, controllerClass))
290290
.withMessageContainingAll(
291291
"Multiple @HttpExchange annotations found on " + controllerClass,
292-
"@" + HttpExchange.class.getName(),
293-
"@" + ExtraHttpExchange.class.getName()
292+
HttpExchange.class.getSimpleName(),
293+
ExtraHttpExchange.class.getSimpleName()
294294
);
295295
}
296296

@@ -305,8 +305,8 @@ void httpExchangeWithMultipleAnnotationsAtMethodLevel() throws NoSuchMethodExcep
305305
.isThrownBy(() -> mapping.getMappingForMethod(method, controllerClass))
306306
.withMessageContainingAll(
307307
"Multiple @HttpExchange annotations found on " + method,
308-
"@" + PostExchange.class.getName(),
309-
"@" + PutExchange.class.getName()
308+
PostExchange.class.getSimpleName(),
309+
PutExchange.class.getSimpleName()
310310
);
311311
}
312312

@@ -322,8 +322,8 @@ void httpExchangeWithMixedAnnotationsAtClassLevel() throws NoSuchMethodException
322322
.withMessageContainingAll(
323323
controllerClass.getName(),
324324
"is annotated with @RequestMapping and @HttpExchange annotations, but only one is allowed:",
325-
"@" + RequestMapping.class.getName(),
326-
"@" + HttpExchange.class.getName()
325+
RequestMapping.class.getSimpleName(),
326+
HttpExchange.class.getSimpleName()
327327
);
328328
}
329329

@@ -339,8 +339,8 @@ void httpExchangeWithMixedAnnotationsAtMethodLevel() throws NoSuchMethodExceptio
339339
.withMessageContainingAll(
340340
method.toString(),
341341
"is annotated with @RequestMapping and @HttpExchange annotations, but only one is allowed:",
342-
"@" + PostMapping.class.getName(),
343-
"@" + PostExchange.class.getName()
342+
PostMapping.class.getSimpleName(),
343+
PostExchange.class.getSimpleName()
344344
);
345345
}
346346

0 commit comments

Comments
 (0)