Skip to content

Commit 0183576

Browse files
committed
Polishing
1 parent db69a08 commit 0183576

File tree

7 files changed

+74
-71
lines changed

7 files changed

+74
-71
lines changed

spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscovererTests.java

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -27,8 +27,7 @@
2727
/**
2828
* Unit tests for the {@link AspectJAdviceParameterNameDiscoverer} class.
2929
*
30-
* <p>See also {@link TigerAspectJAdviceParameterNameDiscovererTests} in
31-
* the 'tiger' tree for tests relating to annotations.
30+
* <p>See also {@link TigerAspectJAdviceParameterNameDiscovererTests} for tests relating to annotations.
3231
*
3332
* @author Adrian Colyer
3433
* @author Chris Beams
@@ -83,27 +82,28 @@ public void testNoArgs() {
8382

8483
@Test
8584
public void testJoinPointOnly() {
86-
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[]{"thisJoinPoint"});
85+
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[] {"thisJoinPoint"});
8786
}
8887

8988
@Test
9089
public void testJoinPointStaticPartOnly() {
91-
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[]{"thisJoinPointStaticPart"});
90+
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[] {"thisJoinPointStaticPart"});
9291
}
9392

9493
@Test
9594
public void testTwoJoinPoints() {
96-
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class, "Failed to bind all argument names: 1 argument(s) could not be bound");
95+
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class,
96+
"Failed to bind all argument names: 1 argument(s) could not be bound");
9797
}
9898

9999
@Test
100100
public void testOneThrowable() {
101-
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[]{"ex"});
101+
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[] {"ex"});
102102
}
103103

104104
@Test
105105
public void testOneJPAndOneThrowable() {
106-
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[]{"thisJoinPoint", "ex"});
106+
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[] {"thisJoinPoint", "ex"});
107107
}
108108

109109
@Test
@@ -120,7 +120,7 @@ public void testThrowableNoCandidates() {
120120

121121
@Test
122122
public void testReturning() {
123-
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[]{"obj"});
123+
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[] {"obj"});
124124
}
125125

126126
@Test
@@ -137,16 +137,16 @@ public void testReturningNoCandidates() {
137137

138138
@Test
139139
public void testThisBindingOneCandidate() {
140-
assertParameterNames(getMethod("oneObject"), "this(x)", new String[]{"x"});
140+
assertParameterNames(getMethod("oneObject"), "this(x)", new String[] {"x"});
141141
}
142142

143143
@Test
144144
public void testThisBindingWithAlternateTokenizations() {
145-
assertParameterNames(getMethod("oneObject"), "this( x )", new String[]{"x"});
146-
assertParameterNames(getMethod("oneObject"), "this( x)", new String[]{"x"});
147-
assertParameterNames(getMethod("oneObject"), "this (x )", new String[]{"x"});
148-
assertParameterNames(getMethod("oneObject"), "this(x )", new String[]{"x"});
149-
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[]{"x"});
145+
assertParameterNames(getMethod("oneObject"), "this( x )", new String[] {"x"});
146+
assertParameterNames(getMethod("oneObject"), "this( x)", new String[] {"x"});
147+
assertParameterNames(getMethod("oneObject"), "this (x )", new String[] {"x"});
148+
assertParameterNames(getMethod("oneObject"), "this(x )", new String[] {"x"});
149+
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[] {"x"});
150150
}
151151

152152
@Test
@@ -165,16 +165,16 @@ public void testThisBindingWithBadPointcutExpressions() {
165165

166166
@Test
167167
public void testTargetBindingOneCandidate() {
168-
assertParameterNames(getMethod("oneObject"), "target(x)", new String[]{"x"});
168+
assertParameterNames(getMethod("oneObject"), "target(x)", new String[] {"x"});
169169
}
170170

171171
@Test
172172
public void testTargetBindingWithAlternateTokenizations() {
173-
assertParameterNames(getMethod("oneObject"), "target( x )", new String[]{"x"});
174-
assertParameterNames(getMethod("oneObject"), "target( x)", new String[]{"x"});
175-
assertParameterNames(getMethod("oneObject"), "target (x )", new String[]{"x"});
176-
assertParameterNames(getMethod("oneObject"), "target(x )", new String[]{"x"});
177-
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[]{"x"});
173+
assertParameterNames(getMethod("oneObject"), "target( x )", new String[] {"x"});
174+
assertParameterNames(getMethod("oneObject"), "target( x)", new String[] {"x"});
175+
assertParameterNames(getMethod("oneObject"), "target (x )", new String[] {"x"});
176+
assertParameterNames(getMethod("oneObject"), "target(x )", new String[] {"x"});
177+
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[] {"x"});
178178
}
179179

180180
@Test
@@ -193,7 +193,7 @@ public void testTargetBindingWithBadPointcutExpressions() {
193193

194194
@Test
195195
public void testArgsBindingOneObject() {
196-
assertParameterNames(getMethod("oneObject"), "args(x)", new String[]{"x"});
196+
assertParameterNames(getMethod("oneObject"), "args(x)", new String[] {"x"});
197197
}
198198

199199
@Test
@@ -210,7 +210,7 @@ public void testAmbiguousArgsBinding() {
210210

211211
@Test
212212
public void testArgsOnePrimitive() {
213-
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[]{"count"});
213+
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[] {"count"});
214214
}
215215

216216
@Test
@@ -221,62 +221,64 @@ public void testArgsOnePrimitiveOneObject() {
221221

222222
@Test
223223
public void testThisAndPrimitive() {
224-
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", new String[]{"obj", "count"});
224+
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", new String[] {"obj", "count"});
225225
}
226226

227227
@Test
228228
public void testTargetAndPrimitive() {
229-
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", new String[]{"obj", "count"});
229+
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", new String[] {"obj", "count"});
230230
}
231231

232232
@Test
233233
public void testThrowingAndPrimitive() {
234-
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", new String[]{"ex", "count"});
234+
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", new String[] {"ex", "count"});
235235
}
236236

237237
@Test
238238
public void testAllTogetherNow() {
239-
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", new String[]{"thisJoinPoint", "ex", "x", "foo"});
239+
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", new String[] {"thisJoinPoint", "ex", "x", "foo"});
240240
}
241241

242242
@Test
243243
public void testReferenceBinding() {
244-
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)",new String[] {"foo"});
244+
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)", new String[] {"foo"});
245245
}
246246

247247
@Test
248248
public void testReferenceBindingWithAlternateTokenizations() {
249-
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)",new String[] {"foo"});
250-
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )",new String[] {"foo"});
251-
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)",new String[] {"foo"});
249+
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)", new String[] {"foo"});
250+
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )", new String[] {"foo"});
251+
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)", new String[] {"foo"});
252252
}
253253

254254

255255
protected Method getMethod(String name) {
256256
// assumes no overloading of test methods...
257257
Method[] candidates = this.getClass().getMethods();
258-
for (int i = 0; i < candidates.length; i++) {
259-
if (candidates[i].getName().equals(name)) {
260-
return candidates[i];
258+
for (Method candidate : candidates) {
259+
if (candidate.getName().equals(name)) {
260+
return candidate;
261261
}
262262
}
263263
fail("Bad test specification, no method '" + name + "' found in test class");
264264
return null;
265265
}
266266

267-
protected void assertParameterNames(Method m, String pointcut, String[] parameterNames) {
268-
assertParameterNames(m, pointcut, null, null, parameterNames);
267+
protected void assertParameterNames(Method method, String pointcut, String[] parameterNames) {
268+
assertParameterNames(method, pointcut, null, null, parameterNames);
269269
}
270270

271-
protected void assertParameterNames(Method m, String pointcut, String returning, String throwing, String[] parameterNames) {
271+
protected void assertParameterNames(Method method, String pointcut, String returning, String throwing,
272+
String[] parameterNames) {
273+
272274
assertEquals("bad test specification, must have same number of parameter names as method arguments",
273-
m.getParameterCount(), parameterNames.length);
275+
method.getParameterCount(), parameterNames.length);
274276

275277
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
276278
discoverer.setRaiseExceptions(true);
277279
discoverer.setReturningName(returning);
278280
discoverer.setThrowingName(throwing);
279-
String[] discoveredNames = discoverer.getParameterNames(m);
281+
String[] discoveredNames = discoverer.getParameterNames(method);
280282

281283
String formattedExpectedNames = format(parameterNames);
282284
String formattedActualNames = format(discoveredNames);
@@ -294,18 +296,20 @@ protected void assertParameterNames(Method m, String pointcut, String returning,
294296
}
295297
}
296298

297-
protected void assertException(Method m, String pointcut, Class<?> exceptionType, String message) {
298-
assertException(m, pointcut, null, null, exceptionType, message);
299+
protected void assertException(Method method, String pointcut, Class<?> exceptionType, String message) {
300+
assertException(method, pointcut, null, null, exceptionType, message);
299301
}
300302

301-
protected void assertException(Method m, String pointcut, String returning, String throwing, Class<?> exceptionType, String message) {
303+
protected void assertException(Method method, String pointcut, String returning, String throwing,
304+
Class<?> exceptionType, String message) {
305+
302306
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
303307
discoverer.setRaiseExceptions(true);
304308
discoverer.setReturningName(returning);
305309
discoverer.setThrowingName(throwing);
306310

307311
try {
308-
discoverer.getParameterNames(m);
312+
discoverer.getParameterNames(method);
309313
fail("Expecting " + exceptionType.getName() + " with message '" + message + "'");
310314
}
311315
catch (RuntimeException expected) {

spring-aop/src/test/java/org/springframework/aop/aspectj/TigerAspectJAdviceParameterNameDiscovererTests.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -27,55 +27,54 @@
2727
* @author Adrian Colyer
2828
* @author Chris Beams
2929
*/
30-
public class TigerAspectJAdviceParameterNameDiscovererTests
31-
extends AspectJAdviceParameterNameDiscovererTests {
30+
public class TigerAspectJAdviceParameterNameDiscovererTests extends AspectJAdviceParameterNameDiscovererTests {
3231

3332
@Test
3433
public void testAtThis() {
35-
assertParameterNames(getMethod("oneAnnotation"),"@this(a)",new String[]{"a"});
34+
assertParameterNames(getMethod("oneAnnotation"),"@this(a)", new String[] {"a"});
3635
}
3736

3837
@Test
3938
public void testAtTarget() {
40-
assertParameterNames(getMethod("oneAnnotation"),"@target(a)",new String[]{"a"});
39+
assertParameterNames(getMethod("oneAnnotation"),"@target(a)", new String[] {"a"});
4140
}
4241

4342
@Test
4443
public void testAtArgs() {
45-
assertParameterNames(getMethod("oneAnnotation"),"@args(a)",new String[]{"a"});
44+
assertParameterNames(getMethod("oneAnnotation"),"@args(a)", new String[] {"a"});
4645
}
4746

4847
@Test
4948
public void testAtWithin() {
50-
assertParameterNames(getMethod("oneAnnotation"),"@within(a)",new String[]{"a"});
49+
assertParameterNames(getMethod("oneAnnotation"),"@within(a)", new String[] {"a"});
5150
}
5251

5352
@Test
5453
public void testAtWithincode() {
55-
assertParameterNames(getMethod("oneAnnotation"),"@withincode(a)",new String[]{"a"});
54+
assertParameterNames(getMethod("oneAnnotation"),"@withincode(a)", new String[] {"a"});
5655
}
5756

5857
@Test
5958
public void testAtAnnotation() {
60-
assertParameterNames(getMethod("oneAnnotation"),"@annotation(a)",new String[]{"a"});
59+
assertParameterNames(getMethod("oneAnnotation"),"@annotation(a)", new String[] {"a"});
6160
}
6261

6362
@Test
6463
public void testAmbiguousAnnotationTwoVars() {
65-
assertException(getMethod("twoAnnotations"),"@annotation(a) && @this(x)",AmbiguousBindingException.class,
64+
assertException(getMethod("twoAnnotations"),"@annotation(a) && @this(x)", AmbiguousBindingException.class,
6665
"Found 2 potential annotation variable(s), and 2 potential argument slots");
6766
}
6867

6968
@Test
7069
public void testAmbiguousAnnotationOneVar() {
7170
assertException(getMethod("oneAnnotation"),"@annotation(a) && @this(x)",IllegalArgumentException.class,
72-
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
71+
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
7372
}
7473

7574
@Test
7675
public void testAnnotationMedley() {
77-
assertParameterNames(getMethod("annotationMedley"),"@annotation(a) && args(count) && this(foo)",null,"ex",
78-
new String[] {"ex","foo","count","a"});
76+
assertParameterNames(getMethod("annotationMedley"),"@annotation(a) && args(count) && this(foo)",
77+
null, "ex", new String[] {"ex", "foo", "count", "a"});
7978
}
8079

8180

spring-web/src/main/java/org/springframework/http/converter/protobuf/ExtensionRegistryInitializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -22,12 +22,12 @@
2222
* Google Protocol Messages can contain message extensions that can be parsed if
2323
* the appropriate configuration has been registered in the {@code ExtensionRegistry}.
2424
*
25-
* This interface provides a facility to populate the {@code ExtensionRegistry}.
25+
* <p>This interface provides a facility to populate the {@code ExtensionRegistry}.
2626
*
2727
* @author Alex Antonov
2828
* @since 4.1
2929
* @see <a href="https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/ExtensionRegistry">
30-
* com.google.protobuf.ExtensionRegistry</a>
30+
* com.google.protobuf.ExtensionRegistry</a>
3131
*/
3232
public interface ExtensionRegistryInitializer {
3333

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private enum State {NEW, COMMITTING, COMMITTED}
7575

7676

7777
public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory) {
78-
Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null");
78+
Assert.notNull(dataBufferFactory, "DataBufferFactory must not be null");
7979
this.dataBufferFactory = dataBufferFactory;
8080
this.headers = new HttpHeaders();
8181
this.cookies = new LinkedMultiValueMap<>();

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicate.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
/**
2424
* Represents a function that evaluates on a given {@link ServerRequest}.
25-
* Instances of this function that evaluate on common request properties can be found in {@link RequestPredicates}.
25+
* Instances of this function that evaluate on common request properties
26+
* can be found in {@link RequestPredicates}.
2627
*
2728
* @author Arjen Poutsma
2829
* @since 5.0
@@ -74,17 +75,17 @@ default RequestPredicate or(RequestPredicate other) {
7475

7576
/**
7677
* Transform the given request into a request used for a nested route. For instance,
77-
* a path-based predicate can return a {@code ServerRequest} with a the path remaining after a
78-
* match.
78+
* a path-based predicate can return a {@code ServerRequest} with a the path remaining
79+
* after a match.
7980
* <p>The default implementation returns an {@code Optional} wrapping the given path if
80-
* {@link #test(ServerRequest)} evaluates to {@code true}; or {@link Optional#empty()} if it
81-
* evaluates to {@code false}.
81+
* {@link #test(ServerRequest)} evaluates to {@code true}; or {@link Optional#empty()}
82+
* if it evaluates to {@code false}.
8283
* @param request the request to be nested
8384
* @return the nested request
8485
* @see RouterFunctions#nest(RequestPredicate, RouterFunction)
8586
*/
8687
default Optional<ServerRequest> nest(ServerRequest request) {
87-
return test(request) ? Optional.of(request) : Optional.empty();
88+
return (test(request) ? Optional.of(request) : Optional.empty());
8889
}
8990

9091
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/HandlerFunctionAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -44,10 +44,11 @@ public class HandlerFunctionAdapter implements HandlerAdapter {
4444
HANDLER_FUNCTION_RETURN_TYPE = new MethodParameter(method, -1);
4545
}
4646
catch (NoSuchMethodException ex) {
47-
throw new Error(ex);
47+
throw new IllegalStateException(ex);
4848
}
4949
}
5050

51+
5152
@Override
5253
public boolean supports(Object handler) {
5354
return handler instanceof HandlerFunction;

0 commit comments

Comments
 (0)