Skip to content

Commit 4b6fabb

Browse files
committed
Polishing
1 parent cba2b6e commit 4b6fabb

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object
166166
}
167167
else if (requiredType.isArray()) {
168168
// Array required -> apply appropriate conversion of elements.
169-
if (convertedValue instanceof String text && Enum.class.isAssignableFrom(requiredType.getComponentType())) {
169+
if (convertedValue instanceof String text &&
170+
Enum.class.isAssignableFrom(requiredType.getComponentType())) {
170171
convertedValue = StringUtils.commaDelimitedListToStringArray(text);
171172
}
172173
return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType());

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ else if (containsSingleton(beanName) && !containsBeanDefinition(beanName)) {
583583
Class<?>[] typesToMatch = (FactoryBean.class == classToMatch ?
584584
new Class<?>[] {classToMatch} : new Class<?>[] {FactoryBean.class, classToMatch});
585585

586-
587586
// Attempt to predict the bean type
588587
Class<?> predictedType = null;
589588

spring-beans/src/test/java/org/springframework/beans/factory/annotation/LookupAnnotationTests.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -53,7 +53,6 @@ public void setup() {
5353
@Test
5454
public void testWithoutConstructorArg() {
5555
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
56-
assertThat(bean).isNotNull();
5756
Object expected = bean.get();
5857
assertThat(expected.getClass()).isEqualTo(TestBean.class);
5958
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
@@ -62,7 +61,6 @@ public void testWithoutConstructorArg() {
6261
@Test
6362
public void testWithOverloadedArg() {
6463
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
65-
assertThat(bean).isNotNull();
6664
TestBean expected = bean.get("haha");
6765
assertThat(expected.getClass()).isEqualTo(TestBean.class);
6866
assertThat(expected.getName()).isEqualTo("haha");
@@ -72,7 +70,6 @@ public void testWithOverloadedArg() {
7270
@Test
7371
public void testWithOneConstructorArg() {
7472
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
75-
assertThat(bean).isNotNull();
7673
TestBean expected = bean.getOneArgument("haha");
7774
assertThat(expected.getClass()).isEqualTo(TestBean.class);
7875
assertThat(expected.getName()).isEqualTo("haha");
@@ -82,7 +79,6 @@ public void testWithOneConstructorArg() {
8279
@Test
8380
public void testWithTwoConstructorArg() {
8481
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
85-
assertThat(bean).isNotNull();
8682
TestBean expected = bean.getTwoArguments("haha", 72);
8783
assertThat(expected.getClass()).isEqualTo(TestBean.class);
8884
assertThat(expected.getName()).isEqualTo("haha");
@@ -93,7 +89,6 @@ public void testWithTwoConstructorArg() {
9389
@Test
9490
public void testWithThreeArgsShouldFail() {
9591
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
96-
assertThat(bean).isNotNull();
9792
assertThatExceptionOfType(AbstractMethodError.class).as("TestBean has no three arg constructor").isThrownBy(() ->
9893
bean.getThreeArguments("name", 1, 2));
9994
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
@@ -102,7 +97,6 @@ public void testWithThreeArgsShouldFail() {
10297
@Test
10398
public void testWithEarlyInjection() {
10499
AbstractBean bean = beanFactory.getBean("beanConsumer", BeanConsumer.class).abstractBean;
105-
assertThat(bean).isNotNull();
106100
Object expected = bean.get();
107101
assertThat(expected.getClass()).isEqualTo(TestBean.class);
108102
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
@@ -115,7 +109,6 @@ public void testWithNullBean() {
115109
beanFactory.registerBeanDefinition("testBean", tbd);
116110

117111
AbstractBean bean = beanFactory.getBean("beanConsumer", BeanConsumer.class).abstractBean;
118-
assertThat(bean).isNotNull();
119112
Object expected = bean.get();
120113
assertThat(expected).isNull();
121114
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
@@ -128,7 +121,6 @@ public void testWithGenericBean() {
128121
beanFactory.registerBeanDefinition("floatStore", new RootBeanDefinition(FloatStore.class));
129122

130123
NumberBean bean = (NumberBean) beanFactory.getBean("numberBean");
131-
assertThat(bean).isNotNull();
132124
assertThat(beanFactory.getBean(DoubleStore.class)).isSameAs(bean.getDoubleStore());
133125
assertThat(beanFactory.getBean(FloatStore.class)).isSameAs(bean.getFloatStore());
134126
}

spring-context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void resourceArrayPropertyEditor() throws IOException {
226226
}
227227

228228
@Test
229-
void childWithProxy() throws Exception {
229+
void childWithProxy() {
230230
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
231231
ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
232232
new String[] {CHILD_WITH_PROXY_CONTEXT}, ctx);
@@ -337,8 +337,7 @@ public Resource getResource(String location) {
337337
};
338338
ResourceTestBean resource1 = (ResourceTestBean) ctx.getBean("resource1");
339339
ResourceTestBean resource2 = (ResourceTestBean) ctx.getBean("resource2");
340-
boolean condition = resource1.getResource() instanceof ClassPathResource;
341-
assertThat(condition).isTrue();
340+
assertThat(resource1.getResource()).isInstanceOf(ClassPathResource.class);
342341
StringWriter writer = new StringWriter();
343342
FileCopyUtils.copy(new InputStreamReader(resource1.getResource().getInputStream()), writer);
344343
assertThat(writer.toString()).isEqualTo("contexttest");

spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private void doTestConversionServiceInApplicationContext(String fileName, Class<
118118
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(fileName, getClass());
119119
ResourceTestBean tb = ctx.getBean("resourceTestBean", ResourceTestBean.class);
120120
assertThat(resourceClass.isInstance(tb.getResource())).isTrue();
121-
assertThat(tb.getResourceArray()).isNotEmpty();
121+
assertThat(tb.getResourceArray()).hasSize(1);
122122
assertThat(resourceClass.isInstance(tb.getResourceArray()[0])).isTrue();
123123
assertThat(tb.getResourceMap()).hasSize(1);
124124
assertThat(resourceClass.isInstance(tb.getResourceMap().get("key1"))).isTrue();

spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ void setup(TestInfo testInfo) throws Exception {
113113
this.baseUrl = "http://localhost:" + this.server.getPort();
114114
}
115115

116+
116117
@AfterEach
117-
void teardown() throws Exception {
118+
void teardown() {
118119
try {
119120
this.sockJsClient.stop();
120121
}
@@ -141,6 +142,7 @@ void teardown() throws Exception {
141142
}
142143
}
143144

145+
144146
protected abstract Class<?> upgradeStrategyConfigClass();
145147

146148
protected abstract WebSocketTestServer createWebSocketTestServer();
@@ -154,6 +156,7 @@ protected void initSockJsClient(Transport... transports) {
154156
this.sockJsClient.start();
155157
}
156158

159+
157160
@Test
158161
void echoWebSocket() throws Exception {
159162
testEcho(100, createWebSocketTransport(), null);
@@ -305,8 +308,8 @@ private static void awaitEvent(BooleanSupplier condition, long timeToWait, Strin
305308
try {
306309
Thread.sleep(timeToSleep);
307310
}
308-
catch (InterruptedException e) {
309-
throw new IllegalStateException("Interrupted while waiting for " + description, e);
311+
catch (InterruptedException ex) {
312+
throw new IllegalStateException("Interrupted while waiting for " + description, ex);
310313
}
311314
}
312315
throw new IllegalStateException("Timed out waiting for " + description);
@@ -333,6 +336,7 @@ public TestServerHandler testServerHandler() {
333336
}
334337
}
335338

339+
336340
private static class TestClientHandler extends TextWebSocketHandler {
337341

338342
private final BlockingQueue<TextMessage> receivedMessages = new LinkedBlockingQueue<>();
@@ -341,7 +345,6 @@ private static class TestClientHandler extends TextWebSocketHandler {
341345

342346
private volatile Throwable transportError;
343347

344-
345348
@Override
346349
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
347350
this.session = session;
@@ -376,6 +379,7 @@ else if (this.transportError != null) {
376379
}
377380
}
378381

382+
379383
private static class EchoHandler extends TextWebSocketHandler {
380384

381385
@Override
@@ -384,21 +388,23 @@ protected void handleTextMessage(WebSocketSession session, TextMessage message)
384388
}
385389
}
386390

391+
387392
private static class TestServerHandler extends TextWebSocketHandler {
388393

389394
private WebSocketSession session;
390395

391396
@Override
392-
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
397+
public void afterConnectionEstablished(WebSocketSession session) {
393398
this.session = session;
394399
}
395400

396-
public WebSocketSession awaitSession(long timeToWait) throws InterruptedException {
401+
public WebSocketSession awaitSession(long timeToWait) {
397402
awaitEvent(() -> this.session != null, timeToWait, " session");
398403
return this.session;
399404
}
400405
}
401406

407+
402408
private static class TestFilter implements Filter {
403409

404410
private final Map<String, HttpHeaders> requests = new HashMap<>();
@@ -407,7 +413,6 @@ private static class TestFilter implements Filter {
407413

408414
private final Map<String, Integer> sendErrorMap = new HashMap<>();
409415

410-
411416
@Override
412417
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
413418
throws IOException, ServletException {
@@ -418,18 +423,18 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
418423
this.requests.put(uri, headers);
419424

420425
for (String suffix : this.sleepDelayMap.keySet()) {
421-
if ((httpRequest).getRequestURI().endsWith(suffix)) {
426+
if (httpRequest.getRequestURI().endsWith(suffix)) {
422427
try {
423428
Thread.sleep(this.sleepDelayMap.get(suffix));
424429
break;
425430
}
426-
catch (InterruptedException e) {
427-
e.printStackTrace();
431+
catch (InterruptedException ex) {
432+
ex.printStackTrace();
428433
}
429434
}
430435
}
431436
for (String suffix : this.sendErrorMap.keySet()) {
432-
if ((httpRequest).getRequestURI().endsWith(suffix)) {
437+
if (httpRequest.getRequestURI().endsWith(suffix)) {
433438
((HttpServletResponse) response).sendError(this.sendErrorMap.get(suffix));
434439
return;
435440
}

0 commit comments

Comments
 (0)