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
This commit is contained in:
Phillip Webb
2018-06-13 21:36:42 -07:00
committed by Juergen Hoeller
parent 81451aa800
commit 1c25cec44f
17 changed files with 99 additions and 100 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@ public class StreamConverterTests {
public void convertFromStreamToList() throws NoSuchFieldException {
this.conversionService.addConverter(Number.class, String.class, new ObjectToStringConverter());
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("listOfStrings")); ;
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("listOfStrings"));
Object result = this.conversionService.convert(stream, listOfStrings);
assertNotNull("Converted object must not be null", result);
@@ -80,7 +80,7 @@ public class StreamConverterTests {
public void convertFromStreamToArray() throws NoSuchFieldException {
this.conversionService.addConverterFactory(new NumberToNumberConverterFactory());
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs")); ;
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
Object result = this.conversionService.convert(stream, arrayOfLongs);
assertNotNull("Converted object must not be null", result);
@@ -95,7 +95,7 @@ public class StreamConverterTests {
@Test
public void convertFromStreamToRawList() throws NoSuchFieldException {
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList")); ;
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList"));
Object result = this.conversionService.convert(stream, listOfStrings);
assertNotNull("Converted object must not be null", result);
@@ -111,7 +111,7 @@ public class StreamConverterTests {
@Test
public void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs")); ;
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
thrown.expect(ConversionFailedException.class);
thrown.expectCause(is(instanceOf(ConverterNotFoundException.class)));
@@ -123,7 +123,7 @@ public class StreamConverterTests {
public void convertFromListToStream() throws NoSuchFieldException {
this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
List<String> stream = Arrays.asList("1", "2", "3");
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers")); ;
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers"));
Object result = this.conversionService.convert(stream, streamOfInteger);
assertNotNull("Converted object must not be null", result);
@@ -143,7 +143,7 @@ public class StreamConverterTests {
return source == 1;
}
});
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans")); ;
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans"));
Object result = this.conversionService.convert(stream, streamOfBoolean);
assertNotNull("Converted object must not be null", result);
@@ -157,7 +157,7 @@ public class StreamConverterTests {
@SuppressWarnings("resource")
public void convertFromListToRawStream() throws NoSuchFieldException {
List<String> stream = Arrays.asList("1", "2", "3");
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream")); ;
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream"));
Object result = this.conversionService.convert(stream, streamOfInteger);
assertNotNull("Converted object must not be null", result);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,30 +38,30 @@ public class ExponentialBackOffTests {
public void defaultInstance() {
ExponentialBackOff backOff = new ExponentialBackOff();
BackOffExecution execution = backOff.start();
assertEquals(2000l, execution.nextBackOff());
assertEquals(3000l, execution.nextBackOff());
assertEquals(4500l, execution.nextBackOff());
assertEquals(2000L, execution.nextBackOff());
assertEquals(3000L, execution.nextBackOff());
assertEquals(4500L, execution.nextBackOff());
}
@Test
public void simpleIncrease() {
ExponentialBackOff backOff = new ExponentialBackOff(100L, 2.0);
BackOffExecution execution = backOff.start();
assertEquals(100l, execution.nextBackOff());
assertEquals(200l, execution.nextBackOff());
assertEquals(400l, execution.nextBackOff());
assertEquals(800l, execution.nextBackOff());
assertEquals(100L, execution.nextBackOff());
assertEquals(200L, execution.nextBackOff());
assertEquals(400L, execution.nextBackOff());
assertEquals(800L, execution.nextBackOff());
}
@Test
public void fixedIncrease() {
ExponentialBackOff backOff = new ExponentialBackOff(100L, 1.0);
backOff.setMaxElapsedTime(300l);
backOff.setMaxElapsedTime(300L);
BackOffExecution execution = backOff.start();
assertEquals(100l, execution.nextBackOff());
assertEquals(100l, execution.nextBackOff());
assertEquals(100l, execution.nextBackOff());
assertEquals(100L, execution.nextBackOff());
assertEquals(100L, execution.nextBackOff());
assertEquals(100L, execution.nextBackOff());
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
}
@@ -71,10 +71,10 @@ public class ExponentialBackOffTests {
backOff.setMaxInterval(4000L);
BackOffExecution execution = backOff.start();
assertEquals(2000l, execution.nextBackOff());
assertEquals(4000l, execution.nextBackOff());
assertEquals(4000l, execution.nextBackOff()); // max reached
assertEquals(4000l, execution.nextBackOff());
assertEquals(2000L, execution.nextBackOff());
assertEquals(4000L, execution.nextBackOff());
assertEquals(4000L, execution.nextBackOff()); // max reached
assertEquals(4000L, execution.nextBackOff());
}
@Test
@@ -83,8 +83,8 @@ public class ExponentialBackOffTests {
backOff.setMaxElapsedTime(4000L);
BackOffExecution execution = backOff.start();
assertEquals(2000l, execution.nextBackOff());
assertEquals(4000l, execution.nextBackOff());
assertEquals(2000L, execution.nextBackOff());
assertEquals(4000L, execution.nextBackOff());
assertEquals(BackOffExecution.STOP, execution.nextBackOff()); // > 4 sec wait in total
}
@@ -98,10 +98,10 @@ public class ExponentialBackOffTests {
BackOffExecution execution = backOff.start();
BackOffExecution execution2 = backOff.start();
assertEquals(2000l, execution.nextBackOff());
assertEquals(2000l, execution2.nextBackOff());
assertEquals(4000l, execution.nextBackOff());
assertEquals(4000l, execution2.nextBackOff());
assertEquals(2000L, execution.nextBackOff());
assertEquals(2000L, execution2.nextBackOff());
assertEquals(4000L, execution.nextBackOff());
assertEquals(4000L, execution2.nextBackOff());
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
assertEquals(BackOffExecution.STOP, execution2.nextBackOff());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +48,8 @@ public class FixedBackOffTests {
public void maxAttemptsReached() {
FixedBackOff backOff = new FixedBackOff(200L, 2);
BackOffExecution execution = backOff.start();
assertEquals(200l, execution.nextBackOff());
assertEquals(200l, execution.nextBackOff());
assertEquals(200L, execution.nextBackOff());
assertEquals(200L, execution.nextBackOff());
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
}
@@ -59,8 +59,8 @@ public class FixedBackOffTests {
BackOffExecution execution = backOff.start();
BackOffExecution execution2 = backOff.start();
assertEquals(100l, execution.nextBackOff());
assertEquals(100l, execution2.nextBackOff());
assertEquals(100L, execution.nextBackOff());
assertEquals(100L, execution2.nextBackOff());
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
assertEquals(BackOffExecution.STOP, execution2.nextBackOff());
}
@@ -69,12 +69,12 @@ public class FixedBackOffTests {
public void liveUpdate() {
FixedBackOff backOff = new FixedBackOff(100L, 1);
BackOffExecution execution = backOff.start();
assertEquals(100l, execution.nextBackOff());
assertEquals(100L, execution.nextBackOff());
backOff.setInterval(200l);
backOff.setInterval(200L);
backOff.setMaxAttempts(2);
assertEquals(200l, execution.nextBackOff());
assertEquals(200L, execution.nextBackOff());
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
}

View File

@@ -271,7 +271,7 @@ public class ObjectUtilsTests {
@Test
@Deprecated
public void hashCodeWithLong() {
long lng = 883l;
long lng = 883L;
int expected = (new Long(lng)).hashCode();
assertEquals(expected, ObjectUtils.hashCode(lng));
}
@@ -489,12 +489,12 @@ public class ObjectUtilsTests {
@Test
public void nullSafeHashCodeWithLongArray() {
long lng = 7993l;
long lng = 7993L;
int expected = 31 * 7 + (int) (lng ^ (lng >>> 32));
lng = 84320l;
lng = 84320L;
expected = 31 * expected + (int) (lng ^ (lng >>> 32));
long[] array = {7993l, 84320l};
long[] array = {7993L, 84320L};
int actual = ObjectUtils.nullSafeHashCode(array);
assertEquals(expected, actual);
@@ -715,7 +715,7 @@ public class ObjectUtilsTests {
@Test
public void nullSafeToStringWithLongArray() {
long[] array = {434l, 23423l};
long[] array = {434L, 23423L};
assertEquals("{434, 23423}", ObjectUtils.nullSafeToString(array));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -227,7 +227,7 @@ public abstract class AbstractStaxXMLReaderTestCase {
if (arguments[i] instanceof Attributes) {
arguments[i] = new PartialAttributes((Attributes) arguments[i]);
}
};
}
return arguments;
}
}