Skip to content

Commit 3b810f3

Browse files
committed
Consistent Class array vs vararg declarations (and related polishing)
1 parent 46cbdff commit 3b810f3

File tree

39 files changed

+388
-413
lines changed

39 files changed

+388
-413
lines changed

spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 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.
@@ -47,7 +47,7 @@ public class ConcurrencyThrottleInterceptorTests {
4747
public void testSerializable() throws Exception {
4848
DerivedTestBean tb = new DerivedTestBean();
4949
ProxyFactory proxyFactory = new ProxyFactory();
50-
proxyFactory.setInterfaces(new Class[] {ITestBean.class});
50+
proxyFactory.setInterfaces(ITestBean.class);
5151
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
5252
proxyFactory.addAdvice(cti);
5353
proxyFactory.setTarget(tb);
@@ -75,7 +75,7 @@ public void testMultipleThreadsWithLimit10() {
7575
private void testMultipleThreads(int concurrencyLimit) {
7676
TestBean tb = new TestBean();
7777
ProxyFactory proxyFactory = new ProxyFactory();
78-
proxyFactory.setInterfaces(new Class[] {ITestBean.class});
78+
proxyFactory.setInterfaces(ITestBean.class);
7979
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
8080
cti.setConcurrencyLimit(concurrencyLimit);
8181
proxyFactory.addAdvice(cti);
@@ -95,7 +95,7 @@ private void testMultipleThreads(int concurrencyLimit) {
9595
ex.printStackTrace();
9696
}
9797
threads[i] = new ConcurrencyThread(proxy,
98-
i % 2 == 0 ? (Throwable) new OutOfMemoryError() : (Throwable) new IllegalStateException());
98+
i % 2 == 0 ? new OutOfMemoryError() : new IllegalStateException());
9999
threads[i].start();
100100
}
101101
for (int i = 0; i < NR_OF_THREADS; i++) {

spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 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.
@@ -83,7 +83,7 @@ public void testSetExceptionMethodWithReturnValuePlaceholder() {
8383
public void testSunnyDayPathLogsCorrectly() throws Throwable {
8484

8585
MethodInvocation methodInvocation = mock(MethodInvocation.class);
86-
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{}));
86+
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
8787
given(methodInvocation.getThis()).willReturn(this);
8888

8989
Log log = mock(Log.class);
@@ -101,7 +101,7 @@ public void testExceptionPathLogsCorrectly() throws Throwable {
101101
MethodInvocation methodInvocation = mock(MethodInvocation.class);
102102

103103
IllegalArgumentException exception = new IllegalArgumentException();
104-
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{}));
104+
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
105105
given(methodInvocation.getThis()).willReturn(this);
106106
given(methodInvocation.proceed()).willThrow(exception);
107107

spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 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.
@@ -34,7 +34,7 @@ public class SimpleTraceInterceptorTests {
3434
@Test
3535
public void testSunnyDayPathLogsCorrectly() throws Throwable {
3636
MethodInvocation mi = mock(MethodInvocation.class);
37-
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{}));
37+
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
3838
given(mi.getThis()).willReturn(this);
3939

4040
Log log = mock(Log.class);
@@ -48,7 +48,7 @@ public void testSunnyDayPathLogsCorrectly() throws Throwable {
4848
@Test
4949
public void testExceptionPathStillLogsCorrectly() throws Throwable {
5050
MethodInvocation mi = mock(MethodInvocation.class);
51-
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{}));
51+
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
5252
given(mi.getThis()).willReturn(this);
5353
IllegalArgumentException exception = new IllegalArgumentException();
5454
given(mi.proceed()).willThrow(exception);

spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java

+7-7
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.
@@ -226,14 +226,14 @@ public void testResolveInvalidSignature() throws Exception {
226226

227227
@Test
228228
public void testResolveWithAndWithoutArgList() throws Exception {
229-
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", new Class[]{String.class, int.class});
229+
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", String.class, int.class);
230230
assertSignatureEquals(desiredMethod, "doSomethingElse");
231231
assertNull(BeanUtils.resolveSignature("doSomethingElse()", MethodSignatureBean.class));
232232
}
233233

234234
@Test
235235
public void testResolveTypedSignature() throws Exception {
236-
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", new Class[]{String.class, int.class});
236+
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", String.class, int.class);
237237
assertSignatureEquals(desiredMethod, "doSomethingElse(java.lang.String, int)");
238238
}
239239

@@ -244,20 +244,20 @@ public void testResolveOverloadedSignature() throws Exception {
244244
assertSignatureEquals(desiredMethod, "overloaded()");
245245

246246
// resolve with single arg
247-
desiredMethod = MethodSignatureBean.class.getMethod("overloaded", new Class[]{String.class});
247+
desiredMethod = MethodSignatureBean.class.getMethod("overloaded", String.class);
248248
assertSignatureEquals(desiredMethod, "overloaded(java.lang.String)");
249249

250250
// resolve with two args
251-
desiredMethod = MethodSignatureBean.class.getMethod("overloaded", new Class[]{String.class, BeanFactory.class});
251+
desiredMethod = MethodSignatureBean.class.getMethod("overloaded", String.class, BeanFactory.class);
252252
assertSignatureEquals(desiredMethod, "overloaded(java.lang.String, org.springframework.beans.factory.BeanFactory)");
253253
}
254254

255255
@Test
256256
public void testResolveSignatureWithArray() throws Exception {
257-
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAnArray", new Class[]{String[].class});
257+
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAnArray", String[].class);
258258
assertSignatureEquals(desiredMethod, "doSomethingWithAnArray(java.lang.String[])");
259259

260-
desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAMultiDimensionalArray", new Class[]{String[][].class});
260+
desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAMultiDimensionalArray", String[][].class);
261261
assertSignatureEquals(desiredMethod, "doSomethingWithAMultiDimensionalArray(java.lang.String[][])");
262262
}
263263

spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java

+21-27
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-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.
@@ -34,60 +34,54 @@ public class AutowireUtilsTests {
3434

3535
@Test
3636
public void genericMethodReturnTypes() {
37-
Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized", new Class[]{});
37+
Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized");
3838
assertEquals(String.class,
3939
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[]{}, getClass().getClassLoader()));
4040

41-
Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments",
42-
new Class[] { Integer.class, Boolean.class });
41+
Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments", Integer.class, Boolean.class);
4342
assertEquals(String.class,
44-
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterizedWithArguments, new Object[] { 99, true }, getClass().getClassLoader()));
43+
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterizedWithArguments, new Object[] {99, true}, getClass().getClassLoader()));
4544

46-
Method createProxy = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createProxy", new Class[] { Object.class });
45+
Method createProxy = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createProxy", Object.class);
4746
assertEquals(String.class,
48-
AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[] { "foo" }, getClass().getClassLoader()));
47+
AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[] {"foo"}, getClass().getClassLoader()));
4948

50-
Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy",
51-
new Class[] { String.class, Object.class });
49+
Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.class);
5250
assertEquals(Long.class,
53-
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[] { "enigma", 99L }, getClass().getClassLoader()));
51+
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[] {"enigma", 99L}, getClass().getClassLoader()));
5452

55-
Method createNamedProxyWithDuplicateTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy",
56-
new Class[] { String.class, Object.class });
53+
Method createNamedProxyWithDuplicateTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.class);
5754
assertEquals(String.class,
58-
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDuplicateTypes, new Object[] { "enigma", "foo" }, getClass().getClassLoader()));
55+
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDuplicateTypes, new Object[] {"enigma", "foo"}, getClass().getClassLoader()));
5956

60-
Method createMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createMock", new Class[] { Class.class });
57+
Method createMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createMock", Class.class);
6158
assertEquals(Runnable.class,
62-
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] { Runnable.class }, getClass().getClassLoader()));
59+
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] {Runnable.class}, getClass().getClassLoader()));
6360
assertEquals(Runnable.class,
64-
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] { Runnable.class.getName() }, getClass().getClassLoader()));
61+
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] {Runnable.class.getName()}, getClass().getClassLoader()));
6562

66-
Method createNamedMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedMock", new Class[] { String.class,
67-
Class.class });
63+
Method createNamedMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedMock", String.class, Class.class);
6864
assertEquals(Runnable.class,
69-
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedMock, new Object[] { "foo", Runnable.class }, getClass().getClassLoader()));
65+
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedMock, new Object[] {"foo", Runnable.class}, getClass().getClassLoader()));
7066

71-
Method createVMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createVMock",
72-
new Class[] { Object.class, Class.class });
67+
Method createVMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createVMock", Object.class, Class.class);
7368
assertEquals(Runnable.class,
74-
AutowireUtils.resolveReturnTypeForFactoryMethod(createVMock, new Object[] { "foo", Runnable.class }, getClass().getClassLoader()));
69+
AutowireUtils.resolveReturnTypeForFactoryMethod(createVMock, new Object[] {"foo", Runnable.class}, getClass().getClassLoader()));
7570

7671
// Ideally we would expect String.class instead of Object.class, but
7772
// resolveReturnTypeForFactoryMethod() does not currently support this form of
7873
// look-up.
79-
Method extractValueFrom = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractValueFrom",
80-
new Class[] { MyInterfaceType.class });
74+
Method extractValueFrom = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractValueFrom", MyInterfaceType.class);
8175
assertEquals(Object.class,
82-
AutowireUtils.resolveReturnTypeForFactoryMethod(extractValueFrom, new Object[] { new MySimpleInterfaceType() }, getClass().getClassLoader()));
76+
AutowireUtils.resolveReturnTypeForFactoryMethod(extractValueFrom, new Object[] {new MySimpleInterfaceType()}, getClass().getClassLoader()));
8377

8478
// Ideally we would expect Boolean.class instead of Object.class, but this
8579
// information is not available at run-time due to type erasure.
8680
Map<Integer, Boolean> map = new HashMap<>();
8781
map.put(0, false);
8882
map.put(1, true);
89-
Method extractMagicValue = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractMagicValue", new Class[] { Map.class });
90-
assertEquals(Object.class, AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[] { map }, getClass().getClassLoader()));
83+
Method extractMagicValue = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractMagicValue", Map.class);
84+
assertEquals(Object.class, AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[] {map}, getClass().getClassLoader()));
9185
}
9286

9387

spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java

+2-2
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.
@@ -139,7 +139,7 @@ protected void refreshHome() throws NamingException {
139139
protected Method getCreateMethod(Object home) throws EjbAccessException {
140140
try {
141141
// Cache the EJB create() method that must be declared on the home interface.
142-
return home.getClass().getMethod("create", (Class[]) null);
142+
return home.getClass().getMethod("create");
143143
}
144144
catch (NoSuchMethodException ex) {
145145
throw new EjbAccessException("EJB home [" + home + "] has no no-arg create() method");

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

+7-24
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.
@@ -34,11 +34,11 @@
3434
import org.springframework.tests.sample.objects.TestObject;
3535
import org.springframework.util.ClassUtils;
3636

37-
import static org.junit.Assert.assertEquals;
38-
37+
import static org.junit.Assert.*;
3938

4039
/**
4140
* Unit tests for {@link Conventions}.
41+
*
4242
* @author Rob Harrop
4343
* @author Sam Brannen
4444
*/
@@ -50,13 +50,10 @@ public class ConventionsTests {
5050

5151
@Test
5252
public void simpleObject() {
53-
5453
assertEquals("Incorrect singular variable name",
5554
"testObject", Conventions.getVariableName(new TestObject()));
56-
5755
assertEquals("Incorrect singular variable name", "testObject",
5856
Conventions.getVariableNameForParameter(getMethodParameter(TestObject.class)));
59-
6057
assertEquals("Incorrect singular variable name", "testObject",
6158
Conventions.getVariableNameForReturnType(getMethodForReturnType(TestObject.class)));
6259
}
@@ -69,13 +66,10 @@ public void array() {
6966

7067
@Test
7168
public void list() {
72-
7369
assertEquals("Incorrect plural List form", "testObjectList",
7470
Conventions.getVariableName(Collections.singletonList(new TestObject())));
75-
7671
assertEquals("Incorrect plural List form", "testObjectList",
7772
Conventions.getVariableNameForParameter(getMethodParameter(List.class)));
78-
7973
assertEquals("Incorrect plural List form", "testObjectList",
8074
Conventions.getVariableNameForReturnType(getMethodForReturnType(List.class)));
8175
}
@@ -88,58 +82,47 @@ public void emptyList() {
8882

8983
@Test
9084
public void set() {
91-
9285
assertEquals("Incorrect plural Set form", "testObjectList",
9386
Conventions.getVariableName(Collections.singleton(new TestObject())));
94-
9587
assertEquals("Incorrect plural Set form", "testObjectList",
9688
Conventions.getVariableNameForParameter(getMethodParameter(Set.class)));
97-
9889
assertEquals("Incorrect plural Set form", "testObjectList",
9990
Conventions.getVariableNameForReturnType(getMethodForReturnType(Set.class)));
10091
}
10192

10293
@Test
103-
public void reactiveParameters() throws Exception {
104-
94+
public void reactiveParameters() {
10595
assertEquals("testObjectMono",
10696
Conventions.getVariableNameForParameter(getMethodParameter(Mono.class)));
107-
10897
assertEquals("testObjectFlux",
10998
Conventions.getVariableNameForParameter(getMethodParameter(Flux.class)));
110-
11199
assertEquals("testObjectSingle",
112100
Conventions.getVariableNameForParameter(getMethodParameter(Single.class)));
113-
114101
assertEquals("testObjectObservable",
115102
Conventions.getVariableNameForParameter(getMethodParameter(Observable.class)));
116103
}
117104

118105
@Test
119-
public void reactiveReturnTypes() throws Exception {
120-
106+
public void reactiveReturnTypes() {
121107
assertEquals("testObjectMono",
122108
Conventions.getVariableNameForReturnType(getMethodForReturnType(Mono.class)));
123-
124109
assertEquals("testObjectFlux",
125110
Conventions.getVariableNameForReturnType(getMethodForReturnType(Flux.class)));
126-
127111
assertEquals("testObjectSingle",
128112
Conventions.getVariableNameForReturnType(getMethodForReturnType(Single.class)));
129-
130113
assertEquals("testObjectObservable",
131114
Conventions.getVariableNameForReturnType(getMethodForReturnType(Observable.class)));
132115
}
133116

134117
@Test
135-
public void attributeNameToPropertyName() throws Exception {
118+
public void attributeNameToPropertyName() {
136119
assertEquals("transactionManager", Conventions.attributeNameToPropertyName("transaction-manager"));
137120
assertEquals("pointcutRef", Conventions.attributeNameToPropertyName("pointcut-ref"));
138121
assertEquals("lookupOnStartup", Conventions.attributeNameToPropertyName("lookup-on-startup"));
139122
}
140123

141124
@Test
142-
public void getQualifiedAttributeName() throws Exception {
125+
public void getQualifiedAttributeName() {
143126
String baseName = "foo";
144127
Class<String> cls = String.class;
145128
String desiredResult = "java.lang.String.foo";

0 commit comments

Comments
 (0)