Polish tests and test fixtures in spring-test

This commit is contained in:
Sam Brannen 2021-10-14 22:12:23 +02:00
parent 9b4f3880b3
commit b8fc79543d
11 changed files with 19 additions and 18 deletions

View File

@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
*/
class MockHttpSessionTests {
private MockHttpSession session = new MockHttpSession();
private final MockHttpSession session = new MockHttpSession();
@Test

View File

@ -118,7 +118,7 @@ class TestContextConcurrencyTests {
private static class TrackingListener implements TestExecutionListener {
private ThreadLocal<String> methodName = new ThreadLocal<>();
private final ThreadLocal<String> methodName = new ThreadLocal<>();
@Override

View File

@ -47,7 +47,7 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.asser
*/
class ContextCacheTests {
private ContextCache contextCache = new DefaultContextCache();
private final ContextCache contextCache = new DefaultContextCache();
@BeforeEach

View File

@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock;
*/
public class SpringFailOnTimeoutTests {
private Statement statement = mock(Statement.class);
private final Statement statement = mock(Statement.class);
@Test

View File

@ -68,16 +68,16 @@ public class Component {
int add(int... args) {
int sum = 0;
for (int i = 0; i < args.length; i++) {
sum += args[i];
for (int arg : args) {
sum += arg;
}
return sum;
}
int multiply(Integer... args) {
int product = 1;
for (int i = 0; i < args.length; i++) {
product *= args[i];
for (Integer arg : args) {
product *= arg;
}
return product;
}

View File

@ -70,10 +70,9 @@ public class Person {
if (this == other) {
return true;
}
if (!(other instanceof Person)) {
if (!(other instanceof Person otherPerson)) {
return false;
}
Person otherPerson = (Person) other;
return (ObjectUtils.nullSafeEquals(this.name, otherPerson.name) &&
ObjectUtils.nullSafeEquals(this.someDouble, otherPerson.someDouble) &&
ObjectUtils.nullSafeEquals(this.someBoolean, otherPerson.someBoolean));

View File

@ -45,8 +45,12 @@ class Person {
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
return false;
}
Person person = (Person) other;
return getName().equals(person.getName());
}

View File

@ -347,7 +347,7 @@ public class PrintingResultHandlerTests {
private String printedHeading;
private Map<String, Map<String, Object>> printedValues = new HashMap<>();
private final Map<String, Map<String, Object>> printedValues = new HashMap<>();
@Override
public void printHeading(String heading) {

View File

@ -117,9 +117,7 @@ public class EncodedUriTests {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof RequestMappingHandlerMapping) {
RequestMappingHandlerMapping requestMappingHandlerMapping = (RequestMappingHandlerMapping) bean;
if (bean instanceof RequestMappingHandlerMapping requestMappingHandlerMapping) {
// URL decode after request mapping, not before.
requestMappingHandlerMapping.setUrlDecode(false);
}

View File

@ -86,7 +86,7 @@ public class HttpOptionsTests {
@Controller
private static class MyController {
private AtomicInteger counter = new AtomicInteger();
private final AtomicInteger counter = new AtomicInteger();
@RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS)

View File

@ -85,7 +85,7 @@ public class FrameworkExtensionTests {
*/
private static class TestRequestPostProcessor implements RequestPostProcessor {
private HttpHeaders headers = new HttpHeaders();
private final HttpHeaders headers = new HttpHeaders();
public TestRequestPostProcessor foo(String value) {