Skip to content

Commit 4c9ed0d

Browse files
committed
Polishing
1 parent 06e6386 commit 4c9ed0d

File tree

4 files changed

+26
-35
lines changed

4 files changed

+26
-35
lines changed

spring-core/src/test/java/org/springframework/core/BridgeMethodResolverTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ public static class ModifiedMessageEvent extends MessageEvent {
806806
}
807807

808808

809-
@SuppressWarnings("unchecked")
809+
@SuppressWarnings({"serial", "unchecked"})
810810
public static class MessageBroadcasterImpl extends GenericEventBroadcasterImpl<MessageEvent>
811811
implements Serializable, // implement an unrelated interface first (SPR-16288)
812812
MessageBroadcaster {

spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -106,8 +106,8 @@ public Method getMostSpecificMethod() {
106106
}
107107
Method method = getMethod();
108108
if (method != null && AopUtils.isAopProxy(this.bean)) {
109-
Class<?> target = AopProxyUtils.ultimateTargetClass(this.bean);
110-
return AopUtils.getMostSpecificMethod(method, target);
109+
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(this.bean);
110+
return AopUtils.getMostSpecificMethod(method, targetClass);
111111
}
112112
else {
113113
return method;

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ErrorsMethodArgumentResolver.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -51,49 +51,44 @@ public boolean supportsParameter(MethodParameter parameter) {
5151
return checkParameterType(parameter, Errors.class::isAssignableFrom);
5252
}
5353

54-
5554
@Override
5655
public Mono<Object> resolveArgument(
5756
MethodParameter parameter, BindingContext context, ServerWebExchange exchange) {
5857

5958
Object errors = getErrors(parameter, context);
60-
6159
if (Mono.class.isAssignableFrom(errors.getClass())) {
6260
return ((Mono<?>) errors).cast(Object.class);
6361
}
6462
else if (Errors.class.isAssignableFrom(errors.getClass())) {
6563
return Mono.just(errors);
6664
}
6765
else {
68-
throw new IllegalStateException(
69-
"Unexpected Errors/BindingResult type: " + errors.getClass().getName());
66+
throw new IllegalStateException("Unexpected Errors/BindingResult type: " + errors.getClass().getName());
7067
}
7168
}
7269

7370
private Object getErrors(MethodParameter parameter, BindingContext context) {
74-
7571
Assert.isTrue(parameter.getParameterIndex() > 0,
76-
"Errors argument must be immediately after a model attribute argument");
72+
"Errors argument must be declared immediately after a model attribute argument");
7773

7874
int index = parameter.getParameterIndex() - 1;
7975
MethodParameter attributeParam = MethodParameter.forExecutable(parameter.getExecutable(), index);
8076
ReactiveAdapter adapter = getAdapterRegistry().getAdapter(attributeParam.getParameterType());
8177

82-
Assert.isNull(adapter, "An @ModelAttribute and an Errors/BindingResult) arguments " +
78+
Assert.state(adapter == null, "An @ModelAttribute and an Errors/BindingResult argument " +
8379
"cannot both be declared with an async type wrapper. " +
8480
"Either declare the @ModelAttribute without an async wrapper type or " +
8581
"handle a WebExchangeBindException error signal through the async type.");
8682

87-
ModelAttribute annot = parameter.getParameterAnnotation(ModelAttribute.class);
88-
String name = (annot != null && StringUtils.hasText(annot.value()) ?
89-
annot.value() : Conventions.getVariableNameForParameter(attributeParam));
90-
83+
ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class);
84+
String name = (ann != null && StringUtils.hasText(ann.value()) ?
85+
ann.value() : Conventions.getVariableNameForParameter(attributeParam));
9186
Object errors = context.getModel().asMap().get(BindingResult.MODEL_KEY_PREFIX + name);
9287

93-
Assert.notNull(errors, "An Errors/BindingResult argument is expected " +
88+
Assert.state(errors != null, () -> "An Errors/BindingResult argument is expected " +
9489
"immediately after the @ModelAttribute argument to which it applies. " +
95-
"For @RequestBody and @RequestPart arguments, please declare them with a reactive type wrapper " +
96-
"and use its onError operators to handle WebExchangeBindException: " +
90+
"For @RequestBody and @RequestPart arguments, please declare them with a reactive " +
91+
"type wrapper and use its onError operators to handle WebExchangeBindException: " +
9792
parameter.getMethod());
9893

9994
return errors;

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsMethodArgumentResolverTests.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -36,12 +36,11 @@
3636
import org.springframework.web.method.ResolvableMethod;
3737
import org.springframework.web.reactive.BindingContext;
3838

39-
import static org.junit.Assert.assertFalse;
40-
import static org.junit.Assert.assertSame;
41-
import static org.junit.Assert.assertTrue;
39+
import static org.junit.Assert.*;
4240

4341
/**
4442
* Unit tests for {@link ErrorsMethodArgumentResolver}.
43+
*
4544
* @author Rossen Stoyanchev
4645
*/
4746
public class ErrorsMethodArgumentResolverTests {
@@ -61,7 +60,7 @@ public class ErrorsMethodArgumentResolverTests {
6160

6261

6362
@Test
64-
public void supports() throws Exception {
63+
public void supports() {
6564
MethodParameter parameter = this.testMethod.arg(Errors.class);
6665
assertTrue(this.resolver.supportsParameter(parameter));
6766

@@ -76,8 +75,7 @@ public void supports() throws Exception {
7675
}
7776

7877
@Test
79-
public void resolve() throws Exception {
80-
78+
public void resolve() {
8179
BindingResult bindingResult = createBindingResult(new Foo(), "foo");
8280
this.bindingContext.getModel().asMap().put(BindingResult.MODEL_KEY_PREFIX + "foo", bindingResult);
8381

@@ -94,8 +92,7 @@ private BindingResult createBindingResult(Foo target, String name) {
9492
}
9593

9694
@Test
97-
public void resolveWithMono() throws Exception {
98-
95+
public void resolveWithMono() {
9996
BindingResult bindingResult = createBindingResult(new Foo(), "foo");
10097
MonoProcessor<BindingResult> monoProcessor = MonoProcessor.create();
10198
monoProcessor.onNext(bindingResult);
@@ -109,19 +106,17 @@ public void resolveWithMono() throws Exception {
109106
}
110107

111108
@Test
112-
public void resolveWithMonoOnBindingResultAndModelAttribute() throws Exception {
113-
114-
this.expectedException.expectMessage("An @ModelAttribute and an Errors/BindingResult) arguments " +
109+
public void resolveWithMonoOnBindingResultAndModelAttribute() {
110+
this.expectedException.expectMessage("An @ModelAttribute and an Errors/BindingResult argument " +
115111
"cannot both be declared with an async type wrapper.");
116112

117113
MethodParameter parameter = this.testMethod.arg(BindingResult.class);
118114
this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
119115
.block(Duration.ofMillis(5000));
120116
}
121117

122-
@Test // SPR-16187
123-
public void resolveWithBindingResultNotFound() throws Exception {
124-
118+
@Test // SPR-16187
119+
public void resolveWithBindingResultNotFound() {
125120
this.expectedException.expectMessage("An Errors/BindingResult argument is expected " +
126121
"immediately after the @ModelAttribute argument");
127122

@@ -159,6 +154,7 @@ void handle(
159154
@ModelAttribute Mono<Foo> fooMono,
160155
BindingResult bindingResult,
161156
Mono<Errors> errorsMono,
162-
String string) {}
157+
String string) {
158+
}
163159

164160
}

0 commit comments

Comments
 (0)