Skip to content

Commit 1c25cec

Browse files
philwebbjhoeller
authored andcommitted
Polish test code
Polish a few issue identified when adding checkstyle to the build. Although checkstyle is not enforcing rules on tests, these are a few minor changes that are still worth making. Issue: SPR-16968
1 parent 81451aa commit 1c25cec

File tree

17 files changed

+99
-100
lines changed

17 files changed

+99
-100
lines changed

spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private void testManyProxies(int howMany) {
175175
ProxyFactory pf1 = new ProxyFactory(target1);
176176
pf1.addAdvice(new NopInterceptor());
177177
pf1.addAdvice(new NopInterceptor());
178-
ITestBean proxies[] = new ITestBean[howMany];
178+
ITestBean[] proxies = new ITestBean[howMany];
179179
for (int i = 0; i < howMany; i++) {
180180
proxies[i] = (ITestBean) createAopProxy(pf1).getProxy();
181181
assertEquals(age1, proxies[i].getAge());
@@ -1356,7 +1356,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
13561356
rmi.getUserAttributes().putAll(valuesToAdd);
13571357
return invocation.proceed();
13581358
}
1359-
};
1359+
}
13601360
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
13611361
MapAwareMethodInterceptor mami1 = new MapAwareMethodInterceptor(new HashMap<>(), new HashMap<String, String>());
13621362
Map<String, String> firstValuesToAdd = new HashMap<>();

spring-context/src/test/java/org/springframework/jmx/export/NotificationPublisherTests.java

+2-2
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-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.
@@ -191,7 +191,7 @@ public AttributeList setAttributes(AttributeList attributes) {
191191
}
192192

193193
@Override
194-
public Object invoke(String actionName, Object params[], String signature[]) throws MBeanException,
194+
public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException,
195195
ReflectionException {
196196
return null;
197197
}

spring-context/src/test/java/org/springframework/jmx/export/annotation/AnnotationTestBean.java

+2-2
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.
@@ -109,7 +109,7 @@ public void dontExposeMe() {
109109
@ManagedMetric(description="The QueueSize metric", currencyTimeLimit = 20, persistPolicy="OnUpdate", persistPeriod=300,
110110
category="utilization", metricType = MetricType.COUNTER, displayName="Queue Size", unit="messages")
111111
public long getQueueSize() {
112-
return 100l;
112+
return 100L;
113113
}
114114

115115
@ManagedMetric

spring-context/src/test/java/org/springframework/jndi/JndiTemplateTests.java

+1-2
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.
@@ -156,7 +156,6 @@ protected Context createInitialContext() {
156156
jt.rebind(name, o);
157157
verify(context).rebind(name, o);
158158
verify(context).close();
159-
;
160159
}
161160

162161
@Test

spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 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.
@@ -63,7 +63,7 @@ public void setup() {
6363
public void convertFromStreamToList() throws NoSuchFieldException {
6464
this.conversionService.addConverter(Number.class, String.class, new ObjectToStringConverter());
6565
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
66-
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("listOfStrings")); ;
66+
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("listOfStrings"));
6767
Object result = this.conversionService.convert(stream, listOfStrings);
6868

6969
assertNotNull("Converted object must not be null", result);
@@ -80,7 +80,7 @@ public void convertFromStreamToList() throws NoSuchFieldException {
8080
public void convertFromStreamToArray() throws NoSuchFieldException {
8181
this.conversionService.addConverterFactory(new NumberToNumberConverterFactory());
8282
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
83-
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs")); ;
83+
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
8484
Object result = this.conversionService.convert(stream, arrayOfLongs);
8585

8686
assertNotNull("Converted object must not be null", result);
@@ -95,7 +95,7 @@ public void convertFromStreamToArray() throws NoSuchFieldException {
9595
@Test
9696
public void convertFromStreamToRawList() throws NoSuchFieldException {
9797
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
98-
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList")); ;
98+
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList"));
9999
Object result = this.conversionService.convert(stream, listOfStrings);
100100

101101
assertNotNull("Converted object must not be null", result);
@@ -111,7 +111,7 @@ public void convertFromStreamToRawList() throws NoSuchFieldException {
111111
@Test
112112
public void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
113113
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
114-
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs")); ;
114+
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
115115

116116
thrown.expect(ConversionFailedException.class);
117117
thrown.expectCause(is(instanceOf(ConverterNotFoundException.class)));
@@ -123,7 +123,7 @@ public void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
123123
public void convertFromListToStream() throws NoSuchFieldException {
124124
this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
125125
List<String> stream = Arrays.asList("1", "2", "3");
126-
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers")); ;
126+
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers"));
127127
Object result = this.conversionService.convert(stream, streamOfInteger);
128128

129129
assertNotNull("Converted object must not be null", result);
@@ -143,7 +143,7 @@ public Boolean convert(Integer source) {
143143
return source == 1;
144144
}
145145
});
146-
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans")); ;
146+
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans"));
147147
Object result = this.conversionService.convert(stream, streamOfBoolean);
148148

149149
assertNotNull("Converted object must not be null", result);
@@ -157,7 +157,7 @@ public Boolean convert(Integer source) {
157157
@SuppressWarnings("resource")
158158
public void convertFromListToRawStream() throws NoSuchFieldException {
159159
List<String> stream = Arrays.asList("1", "2", "3");
160-
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream")); ;
160+
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream"));
161161
Object result = this.conversionService.convert(stream, streamOfInteger);
162162

163163
assertNotNull("Converted object must not be null", result);

spring-core/src/test/java/org/springframework/util/ExponentialBackOffTests.java

+22-22
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-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.
@@ -38,30 +38,30 @@ public class ExponentialBackOffTests {
3838
public void defaultInstance() {
3939
ExponentialBackOff backOff = new ExponentialBackOff();
4040
BackOffExecution execution = backOff.start();
41-
assertEquals(2000l, execution.nextBackOff());
42-
assertEquals(3000l, execution.nextBackOff());
43-
assertEquals(4500l, execution.nextBackOff());
41+
assertEquals(2000L, execution.nextBackOff());
42+
assertEquals(3000L, execution.nextBackOff());
43+
assertEquals(4500L, execution.nextBackOff());
4444
}
4545

4646
@Test
4747
public void simpleIncrease() {
4848
ExponentialBackOff backOff = new ExponentialBackOff(100L, 2.0);
4949
BackOffExecution execution = backOff.start();
50-
assertEquals(100l, execution.nextBackOff());
51-
assertEquals(200l, execution.nextBackOff());
52-
assertEquals(400l, execution.nextBackOff());
53-
assertEquals(800l, execution.nextBackOff());
50+
assertEquals(100L, execution.nextBackOff());
51+
assertEquals(200L, execution.nextBackOff());
52+
assertEquals(400L, execution.nextBackOff());
53+
assertEquals(800L, execution.nextBackOff());
5454
}
5555

5656
@Test
5757
public void fixedIncrease() {
5858
ExponentialBackOff backOff = new ExponentialBackOff(100L, 1.0);
59-
backOff.setMaxElapsedTime(300l);
59+
backOff.setMaxElapsedTime(300L);
6060

6161
BackOffExecution execution = backOff.start();
62-
assertEquals(100l, execution.nextBackOff());
63-
assertEquals(100l, execution.nextBackOff());
64-
assertEquals(100l, execution.nextBackOff());
62+
assertEquals(100L, execution.nextBackOff());
63+
assertEquals(100L, execution.nextBackOff());
64+
assertEquals(100L, execution.nextBackOff());
6565
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
6666
}
6767

@@ -71,10 +71,10 @@ public void maxIntervalReached() {
7171
backOff.setMaxInterval(4000L);
7272

7373
BackOffExecution execution = backOff.start();
74-
assertEquals(2000l, execution.nextBackOff());
75-
assertEquals(4000l, execution.nextBackOff());
76-
assertEquals(4000l, execution.nextBackOff()); // max reached
77-
assertEquals(4000l, execution.nextBackOff());
74+
assertEquals(2000L, execution.nextBackOff());
75+
assertEquals(4000L, execution.nextBackOff());
76+
assertEquals(4000L, execution.nextBackOff()); // max reached
77+
assertEquals(4000L, execution.nextBackOff());
7878
}
7979

8080
@Test
@@ -83,8 +83,8 @@ public void maxAttemptsReached() {
8383
backOff.setMaxElapsedTime(4000L);
8484

8585
BackOffExecution execution = backOff.start();
86-
assertEquals(2000l, execution.nextBackOff());
87-
assertEquals(4000l, execution.nextBackOff());
86+
assertEquals(2000L, execution.nextBackOff());
87+
assertEquals(4000L, execution.nextBackOff());
8888
assertEquals(BackOffExecution.STOP, execution.nextBackOff()); // > 4 sec wait in total
8989
}
9090

@@ -98,10 +98,10 @@ public void startReturnDifferentInstances() {
9898
BackOffExecution execution = backOff.start();
9999
BackOffExecution execution2 = backOff.start();
100100

101-
assertEquals(2000l, execution.nextBackOff());
102-
assertEquals(2000l, execution2.nextBackOff());
103-
assertEquals(4000l, execution.nextBackOff());
104-
assertEquals(4000l, execution2.nextBackOff());
101+
assertEquals(2000L, execution.nextBackOff());
102+
assertEquals(2000L, execution2.nextBackOff());
103+
assertEquals(4000L, execution.nextBackOff());
104+
assertEquals(4000L, execution2.nextBackOff());
105105
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
106106
assertEquals(BackOffExecution.STOP, execution2.nextBackOff());
107107
}

spring-core/src/test/java/org/springframework/util/FixedBackOffTests.java

+8-8
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-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.
@@ -48,8 +48,8 @@ public void noAttemptAtAll() {
4848
public void maxAttemptsReached() {
4949
FixedBackOff backOff = new FixedBackOff(200L, 2);
5050
BackOffExecution execution = backOff.start();
51-
assertEquals(200l, execution.nextBackOff());
52-
assertEquals(200l, execution.nextBackOff());
51+
assertEquals(200L, execution.nextBackOff());
52+
assertEquals(200L, execution.nextBackOff());
5353
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
5454
}
5555

@@ -59,8 +59,8 @@ public void startReturnDifferentInstances() {
5959
BackOffExecution execution = backOff.start();
6060
BackOffExecution execution2 = backOff.start();
6161

62-
assertEquals(100l, execution.nextBackOff());
63-
assertEquals(100l, execution2.nextBackOff());
62+
assertEquals(100L, execution.nextBackOff());
63+
assertEquals(100L, execution2.nextBackOff());
6464
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
6565
assertEquals(BackOffExecution.STOP, execution2.nextBackOff());
6666
}
@@ -69,12 +69,12 @@ public void startReturnDifferentInstances() {
6969
public void liveUpdate() {
7070
FixedBackOff backOff = new FixedBackOff(100L, 1);
7171
BackOffExecution execution = backOff.start();
72-
assertEquals(100l, execution.nextBackOff());
72+
assertEquals(100L, execution.nextBackOff());
7373

74-
backOff.setInterval(200l);
74+
backOff.setInterval(200L);
7575
backOff.setMaxAttempts(2);
7676

77-
assertEquals(200l, execution.nextBackOff());
77+
assertEquals(200L, execution.nextBackOff());
7878
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
7979
}
8080

spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void hashCodeWithFloat() {
271271
@Test
272272
@Deprecated
273273
public void hashCodeWithLong() {
274-
long lng = 883l;
274+
long lng = 883L;
275275
int expected = (new Long(lng)).hashCode();
276276
assertEquals(expected, ObjectUtils.hashCode(lng));
277277
}
@@ -489,12 +489,12 @@ public void nullSafeHashCodeWithIntArrayEqualToNull() {
489489

490490
@Test
491491
public void nullSafeHashCodeWithLongArray() {
492-
long lng = 7993l;
492+
long lng = 7993L;
493493
int expected = 31 * 7 + (int) (lng ^ (lng >>> 32));
494-
lng = 84320l;
494+
lng = 84320L;
495495
expected = 31 * expected + (int) (lng ^ (lng >>> 32));
496496

497-
long[] array = {7993l, 84320l};
497+
long[] array = {7993L, 84320L};
498498
int actual = ObjectUtils.nullSafeHashCode(array);
499499

500500
assertEquals(expected, actual);
@@ -715,7 +715,7 @@ public void nullSafeToStringWithIntArrayEqualToNull() {
715715

716716
@Test
717717
public void nullSafeToStringWithLongArray() {
718-
long[] array = {434l, 23423l};
718+
long[] array = {434L, 23423L};
719719
assertEquals("{434, 23423}", ObjectUtils.nullSafeToString(array));
720720
}
721721

spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.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.
@@ -227,7 +227,7 @@ public Object[] adaptArguments(Object[] arguments) {
227227
if (arguments[i] instanceof Attributes) {
228228
arguments[i] = new PartialAttributes((Attributes) arguments[i]);
229229
}
230-
};
230+
}
231231
return arguments;
232232
}
233233
}

0 commit comments

Comments
 (0)