Skip to content

Commit 0961bc5

Browse files
committed
Polishing
(cherry picked from commit 0b7a24f)
1 parent f2df10c commit 0961bc5

File tree

4 files changed

+70
-68
lines changed

4 files changed

+70
-68
lines changed

spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -55,7 +55,7 @@ abstract class AbstractSchedulingTaskExecutorTests {
5555

5656

5757
@BeforeEach
58-
void setUp(TestInfo testInfo) {
58+
void setup(TestInfo testInfo) {
5959
this.testName = testInfo.getTestMethod().get().getName();
6060
this.threadNamePrefix = this.testName + "-";
6161
this.executor = buildExecutor();
@@ -84,11 +84,11 @@ void executeFailingRunnable() {
8484
TestTask task = new TestTask(this.testName, 0);
8585
executor.execute(task);
8686
Awaitility.await()
87-
.dontCatchUncaughtExceptions()
88-
.atMost(1, TimeUnit.SECONDS)
89-
.pollInterval(10, TimeUnit.MILLISECONDS)
90-
.until(() -> task.exception.get() != null && task.exception.get().getMessage().equals(
91-
"TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>"));
87+
.dontCatchUncaughtExceptions()
88+
.atMost(1, TimeUnit.SECONDS)
89+
.pollInterval(10, TimeUnit.MILLISECONDS)
90+
.until(() -> task.exception.get() != null && task.exception.get().getMessage().equals(
91+
"TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>"));
9292
}
9393

9494
@Test
@@ -101,7 +101,7 @@ void submitRunnable() throws Exception {
101101
}
102102

103103
@Test
104-
void submitFailingRunnable() throws Exception {
104+
void submitFailingRunnable() {
105105
TestTask task = new TestTask(this.testName, 0);
106106
Future<?> future = executor.submit(task);
107107
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
@@ -121,31 +121,31 @@ void submitRunnableWithGetAfterShutdown() throws Exception {
121121
}
122122

123123
@Test
124-
void submitListenableRunnable() throws Exception {
124+
void submitListenableRunnable() {
125125
TestTask task = new TestTask(this.testName, 1);
126126
// Act
127127
ListenableFuture<?> future = executor.submitListenable(task);
128128
future.addCallback(result -> outcome = result, ex -> outcome = ex);
129129
// Assert
130130
Awaitility.await()
131-
.atMost(1, TimeUnit.SECONDS)
132-
.pollInterval(10, TimeUnit.MILLISECONDS)
133-
.until(future::isDone);
131+
.atMost(1, TimeUnit.SECONDS)
132+
.pollInterval(10, TimeUnit.MILLISECONDS)
133+
.until(future::isDone);
134134
assertThat(outcome).isNull();
135135
assertThreadNamePrefix(task);
136136
}
137137

138138
@Test
139-
void submitFailingListenableRunnable() throws Exception {
139+
void submitFailingListenableRunnable() {
140140
TestTask task = new TestTask(this.testName, 0);
141141
ListenableFuture<?> future = executor.submitListenable(task);
142142
future.addCallback(result -> outcome = result, ex -> outcome = ex);
143143

144144
Awaitility.await()
145-
.dontCatchUncaughtExceptions()
146-
.atMost(1, TimeUnit.SECONDS)
147-
.pollInterval(10, TimeUnit.MILLISECONDS)
148-
.until(() -> future.isDone() && outcome != null);
145+
.dontCatchUncaughtExceptions()
146+
.atMost(1, TimeUnit.SECONDS)
147+
.pollInterval(10, TimeUnit.MILLISECONDS)
148+
.until(() -> future.isDone() && outcome != null);
149149
assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
150150
}
151151

@@ -159,14 +159,13 @@ void submitListenableRunnableWithGetAfterShutdown() throws Exception {
159159
future1.get(1000, TimeUnit.MILLISECONDS);
160160
}
161161
catch (Exception ex) {
162-
/* ignore */
162+
// ignore
163163
}
164164
Awaitility.await()
165-
.atMost(4, TimeUnit.SECONDS)
166-
.pollInterval(10, TimeUnit.MILLISECONDS)
167-
.untilAsserted(() ->
168-
assertThatExceptionOfType(CancellationException.class).isThrownBy(() ->
169-
future2.get(1000, TimeUnit.MILLISECONDS)));
165+
.atMost(4, TimeUnit.SECONDS)
166+
.pollInterval(10, TimeUnit.MILLISECONDS)
167+
.untilAsserted(() -> assertThatExceptionOfType(CancellationException.class)
168+
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
170169
}
171170

172171
@Test
@@ -178,11 +177,11 @@ void submitCallable() throws Exception {
178177
}
179178

180179
@Test
181-
void submitFailingCallable() throws Exception {
180+
void submitFailingCallable() {
182181
TestCallable task = new TestCallable(this.testName, 0);
183182
Future<String> future = executor.submit(task);
184-
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
185-
future.get(1000, TimeUnit.MILLISECONDS));
183+
assertThatExceptionOfType(ExecutionException.class)
184+
.isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS));
186185
assertThat(future.isDone()).isTrue();
187186
}
188187

@@ -196,42 +195,41 @@ void submitCallableWithGetAfterShutdown() throws Exception {
196195
future1.get(1000, TimeUnit.MILLISECONDS);
197196
}
198197
catch (Exception ex) {
199-
/* ignore */
198+
// ignore
200199
}
201200
Awaitility.await()
202-
.atMost(4, TimeUnit.SECONDS)
203-
.pollInterval(10, TimeUnit.MILLISECONDS)
204-
.untilAsserted(() ->
205-
assertThatExceptionOfType(CancellationException.class).isThrownBy(() ->
206-
future2.get(1000, TimeUnit.MILLISECONDS)));
201+
.atMost(4, TimeUnit.SECONDS)
202+
.pollInterval(10, TimeUnit.MILLISECONDS)
203+
.untilAsserted(() -> assertThatExceptionOfType(CancellationException.class)
204+
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
207205
}
208206

209207
@Test
210-
void submitListenableCallable() throws Exception {
208+
void submitListenableCallable() {
211209
TestCallable task = new TestCallable(this.testName, 1);
212210
// Act
213211
ListenableFuture<String> future = executor.submitListenable(task);
214212
future.addCallback(result -> outcome = result, ex -> outcome = ex);
215213
// Assert
216214
Awaitility.await()
217-
.atMost(1, TimeUnit.SECONDS)
218-
.pollInterval(10, TimeUnit.MILLISECONDS)
219-
.until(() -> future.isDone() && outcome != null);
215+
.atMost(1, TimeUnit.SECONDS)
216+
.pollInterval(10, TimeUnit.MILLISECONDS)
217+
.until(() -> future.isDone() && outcome != null);
220218
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
221219
}
222220

223221
@Test
224-
void submitFailingListenableCallable() throws Exception {
222+
void submitFailingListenableCallable() {
225223
TestCallable task = new TestCallable(this.testName, 0);
226224
// Act
227225
ListenableFuture<String> future = executor.submitListenable(task);
228226
future.addCallback(result -> outcome = result, ex -> outcome = ex);
229227
// Assert
230228
Awaitility.await()
231-
.dontCatchUncaughtExceptions()
232-
.atMost(1, TimeUnit.SECONDS)
233-
.pollInterval(10, TimeUnit.MILLISECONDS)
234-
.until(() -> future.isDone() && outcome != null);
229+
.dontCatchUncaughtExceptions()
230+
.atMost(1, TimeUnit.SECONDS)
231+
.pollInterval(10, TimeUnit.MILLISECONDS)
232+
.until(() -> future.isDone() && outcome != null);
235233
assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
236234
}
237235

@@ -296,8 +294,9 @@ public void run() {
296294
}
297295
if (expectedRunCount >= 0) {
298296
if (actualRunCount.incrementAndGet() > expectedRunCount) {
299-
RuntimeException exception = new RuntimeException(String.format("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>",
300-
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get()));
297+
RuntimeException exception = new RuntimeException(String.format(
298+
"%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>",
299+
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get()));
301300
this.exception.set(exception);
302301
throw exception;
303302
}
@@ -329,8 +328,9 @@ public String call() throws Exception {
329328
}
330329
if (expectedRunCount >= 0) {
331330
if (actualRunCount.incrementAndGet() > expectedRunCount) {
332-
throw new RuntimeException(String.format("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>",
333-
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get()));
331+
throw new RuntimeException(String.format(
332+
"%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>",
333+
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get()));
334334
}
335335
}
336336
return Thread.currentThread().getName();

spring-context/src/test/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutorTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,24 @@ void lateSetConcurrentExecutorCallRespectsConfiguredTaskDecorator() {
8989

9090

9191
private static class DecoratedRunnable implements Runnable {
92+
9293
@Override
9394
public void run() {
9495
}
9596
}
9697

98+
9799
private static class RunnableDecorator implements TaskDecorator {
100+
98101
@Override
99102
public Runnable decorate(Runnable runnable) {
100103
return new DecoratedRunnable();
101104
}
102105
}
103106

107+
104108
private static class DecoratedExecutor implements Executor {
109+
105110
@Override
106111
public void execute(Runnable command) {
107112
Assert.state(command instanceof DecoratedRunnable, "TaskDecorator not applied");

spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
class ScheduledExecutorFactoryBeanTests {
4242

4343
@Test
44-
void throwsExceptionIfPoolSizeIsLessThanZero() throws Exception {
44+
void throwsExceptionIfPoolSizeIsLessThanZero() {
4545
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
4646
assertThatIllegalArgumentException().isThrownBy(() -> factory.setPoolSize(-1));
4747
}
4848

4949
@Test
5050
@SuppressWarnings("serial")
51-
void shutdownNowIsPropagatedToTheExecutorOnDestroy() throws Exception {
51+
void shutdownNowIsPropagatedToTheExecutorOnDestroy() {
5252
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
5353

5454
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@@ -66,7 +66,7 @@ protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory th
6666

6767
@Test
6868
@SuppressWarnings("serial")
69-
void shutdownIsPropagatedToTheExecutorOnDestroy() throws Exception {
69+
void shutdownIsPropagatedToTheExecutorOnDestroy() {
7070
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
7171

7272
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@@ -85,7 +85,7 @@ protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory th
8585

8686
@Test
8787
@EnabledForTestGroups(LONG_RUNNING)
88-
void oneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception {
88+
void oneTimeExecutionIsSetUpAndFiresCorrectly() {
8989
Runnable runnable = mock(Runnable.class);
9090

9191
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
@@ -99,7 +99,7 @@ void oneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception {
9999

100100
@Test
101101
@EnabledForTestGroups(LONG_RUNNING)
102-
void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
102+
void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() {
103103
Runnable runnable = mock(Runnable.class);
104104

105105
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
@@ -117,7 +117,7 @@ void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
117117

118118
@Test
119119
@EnabledForTestGroups(LONG_RUNNING)
120-
void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
120+
void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() {
121121
Runnable runnable = mock(Runnable.class);
122122
willThrow(new IllegalStateException()).given(runnable).run();
123123

@@ -137,7 +137,7 @@ void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Excep
137137

138138
@Test
139139
@EnabledForTestGroups(LONG_RUNNING)
140-
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
140+
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() {
141141
Runnable runnable = mock(Runnable.class);
142142

143143
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
@@ -157,7 +157,7 @@ void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exceptio
157157

158158
@Test
159159
@EnabledForTestGroups(LONG_RUNNING)
160-
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
160+
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() {
161161
Runnable runnable = mock(Runnable.class);
162162
willThrow(new IllegalStateException()).given(runnable).run();
163163

@@ -179,7 +179,7 @@ void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() t
179179

180180
@Test
181181
@SuppressWarnings("serial")
182-
void settingThreadFactoryToNullForcesUseOfDefaultButIsOtherwiseCool() throws Exception {
182+
void settingThreadFactoryToNullForcesUseOfDefaultButIsOtherwiseCool() {
183183
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
184184
@Override
185185
protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
@@ -195,7 +195,7 @@ protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory th
195195

196196
@Test
197197
@SuppressWarnings("serial")
198-
void settingRejectedExecutionHandlerToNullForcesUseOfDefaultButIsOtherwiseCool() throws Exception {
198+
void settingRejectedExecutionHandlerToNullForcesUseOfDefaultButIsOtherwiseCool() {
199199
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
200200
@Override
201201
protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
@@ -210,7 +210,7 @@ protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory th
210210
}
211211

212212
@Test
213-
void objectTypeReportsCorrectType() throws Exception {
213+
void objectTypeReportsCorrectType() {
214214
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
215215
assertThat(factory.getObjectType()).isEqualTo(ScheduledExecutorService.class);
216216
}

spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutorTests.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -26,8 +26,8 @@
2626
import org.springframework.core.task.AsyncListenableTaskExecutor;
2727

2828
import static org.assertj.core.api.Assertions.assertThat;
29+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2930
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
30-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3131
import static org.assertj.core.api.InstanceOfAssertFactories.type;
3232

3333
/**
@@ -67,8 +67,7 @@ void modifyCorePoolSizeWithInvalidValueWhileRunning() {
6767
assertThat(executor.getCorePoolSize()).isEqualTo(1);
6868
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1);
6969

70-
assertThatThrownBy(() -> executor.setCorePoolSize(-1))
71-
.isInstanceOf(IllegalArgumentException.class);
70+
assertThatIllegalArgumentException().isThrownBy(() -> executor.setCorePoolSize(-1));
7271

7372
assertThat(executor.getCorePoolSize()).isEqualTo(1);
7473
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1);
@@ -90,8 +89,7 @@ void modifyMaxPoolSizeWithInvalidValueWhileRunning() {
9089
assertThat(executor.getMaxPoolSize()).isEqualTo(1);
9190
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1);
9291

93-
assertThatThrownBy(() -> executor.setMaxPoolSize(0))
94-
.isInstanceOf(IllegalArgumentException.class);
92+
assertThatIllegalArgumentException().isThrownBy(() -> executor.setMaxPoolSize(0));
9593

9694
assertThat(executor.getMaxPoolSize()).isEqualTo(1);
9795
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1);
@@ -113,8 +111,7 @@ void modifyKeepAliveSecondsWithInvalidValueWhileRunning() {
113111
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
114112
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
115113

116-
assertThatThrownBy(() -> executor.setKeepAliveSeconds(-10))
117-
.isInstanceOf(IllegalArgumentException.class);
114+
assertThatIllegalArgumentException().isThrownBy(() -> executor.setKeepAliveSeconds(-10));
118115

119116
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
120117
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
@@ -124,8 +121,8 @@ void modifyKeepAliveSecondsWithInvalidValueWhileRunning() {
124121
void queueCapacityDefault() {
125122
assertThat(executor.getQueueCapacity()).isEqualTo(Integer.MAX_VALUE);
126123
assertThat(executor.getThreadPoolExecutor().getQueue())
127-
.asInstanceOf(type(LinkedBlockingQueue.class))
128-
.extracting(BlockingQueue::remainingCapacity).isEqualTo(Integer.MAX_VALUE);
124+
.asInstanceOf(type(LinkedBlockingQueue.class))
125+
.extracting(BlockingQueue::remainingCapacity).isEqualTo(Integer.MAX_VALUE);
129126
}
130127

131128
@Test
@@ -135,8 +132,8 @@ void queueCapacityZero() {
135132

136133
assertThat(executor.getQueueCapacity()).isZero();
137134
assertThat(executor.getThreadPoolExecutor().getQueue())
138-
.asInstanceOf(type(SynchronousQueue.class))
139-
.extracting(BlockingQueue::remainingCapacity).isEqualTo(0);
135+
.asInstanceOf(type(SynchronousQueue.class))
136+
.extracting(BlockingQueue::remainingCapacity).isEqualTo(0);
140137
}
141138

142139
@Test

0 commit comments

Comments
 (0)