Skip to content

Commit e6b45de

Browse files
hangwang200philwebb
authored andcommitted
Simplify some code
See gh-18438
1 parent e41c5a4 commit e6b45de

File tree

7 files changed

+7
-19
lines changed

7 files changed

+7
-19
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ protected ContextLoader resolveContextLoader(Class<?> testClass,
132132
}
133133

134134
private void addConfigAttributesClasses(ContextConfigurationAttributes configAttributes, Class<?>[] classes) {
135-
List<Class<?>> combined = new ArrayList<>();
136-
combined.addAll(Arrays.asList(classes));
135+
List<Class<?>> combined = new ArrayList<>(Arrays.asList(classes));
137136
if (configAttributes.getClasses() != null) {
138137
combined.addAll(Arrays.asList(configAttributes.getClasses()));
139138
}

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/filter/ExcludeFilterContextCustomizer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ public boolean equals(Object obj) {
4040
if (obj == this) {
4141
return true;
4242
}
43-
if (obj == null || getClass() != obj.getClass()) {
44-
return false;
45-
}
46-
return true;
43+
return obj != null && getClass() == obj.getClass();
4744
}
4845

4946
@Override

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ private void logDuplicateJsonObjectsWarning(List<URL> jsonObjects) {
8080

8181
@Override
8282
public boolean equals(Object obj) {
83-
if (obj == null || obj.getClass() != getClass()) {
84-
return false;
85-
}
86-
return true;
83+
return obj != null && obj.getClass() == getClass();
8784
}
8885

8986
@Override

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/system/OutputCapture.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ PrintStream getParent() {
208208
}
209209

210210
private static PrintStream getSystemStream(PrintStream printStream) {
211-
while (printStream instanceof PrintStreamCapture) {
211+
if (printStream instanceof PrintStreamCapture) {
212212
return ((PrintStreamCapture) printStream).getParent();
213213
}
214214
return printStream;

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplateContextCustomizer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ private void registerTestRestTemplate(BeanDefinitionRegistry registry) {
7878

7979
@Override
8080
public boolean equals(Object obj) {
81-
if (obj == null || obj.getClass() != getClass()) {
82-
return false;
83-
}
84-
return true;
81+
return obj != null && obj.getClass() == getClass();
8582
}
8683

8784
@Override

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/htmlunit/LocalHostWebClient.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.test.web.htmlunit;
1818

1919
import java.io.IOException;
20-
import java.net.MalformedURLException;
2120

2221
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
2322
import com.gargoylesoftware.htmlunit.Page;
@@ -43,8 +42,7 @@ public LocalHostWebClient(Environment environment) {
4342
}
4443

4544
@Override
46-
public <P extends Page> P getPage(String url)
47-
throws IOException, FailingHttpStatusCodeException, MalformedURLException {
45+
public <P extends Page> P getPage(String url) throws IOException, FailingHttpStatusCodeException {
4846
if (url.startsWith("/")) {
4947
String port = this.environment.getProperty("local.server.port", "8080");
5048
url = "http://localhost:" + port + url;

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListenerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void beforeTestMethodShouldInjectMockBeanWhenDirtiesContextAttributeIsSet() thro
9292
given(mockTestContext.getAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE))
9393
.willReturn(Boolean.TRUE);
9494
this.listener.beforeTestMethod(mockTestContext);
95-
verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance), (MockDefinition) any());
95+
verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance), any(MockDefinition.class));
9696
assertThat(this.fieldCaptor.getValue().getName()).isEqualTo("mockBean");
9797
}
9898

0 commit comments

Comments
 (0)