Skip to content

Commit d562f42

Browse files
tamasradumaibin
authored andcommitted
Radutamas/bael 1265 update junit with lambdas (eugenp#3196)
* Code for test article: Different Types of Bean Injection in Spring * Adding jUnits for test article: Different Types of Bean Injection in Spring * BAEL-1265: Adding jUnit for article * BAEL-1265: Closing ExecutorService in jUnit * BAEL-1265: Using lambdas instead of anonymous classes
1 parent 93fc617 commit d562f42

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

‎core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.concurrent.*;
1010

1111
import static junit.framework.TestCase.assertTrue;
12-
import static org.junit.Assert.fail;
1312

1413
public class WaitingForThreadsToFinishTest {
1514

@@ -40,16 +39,13 @@ public void givenMultipleThreads_whenUsingCountDownLatch_thenMainShoudWaitForAll
4039
CountDownLatch latch = new CountDownLatch(2);
4140

4241
for (int i = 0; i < 2; i++) {
43-
WORKER_THREAD_POOL.submit(new Runnable() {
44-
@Override
45-
public void run() {
46-
try {
47-
Thread.sleep(1000);
48-
latch.countDown();
49-
} catch (InterruptedException e) {
50-
e.printStackTrace();
51-
Thread.currentThread().interrupt();
52-
}
42+
WORKER_THREAD_POOL.submit(() -> {
43+
try {
44+
Thread.sleep(1000);
45+
latch.countDown();
46+
} catch (InterruptedException e) {
47+
e.printStackTrace();
48+
Thread.currentThread().interrupt();
5349
}
5450
});
5551
}
@@ -83,13 +79,9 @@ public void givenMultipleThreads_whenInvokeAll_thenMainThreadShouldWaitForAllToF
8379
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
8480

8581
try {
86-
WORKER_THREAD_POOL.submit(new Callable<String>() {
87-
@Override
88-
public String call() throws Exception {
89-
fail("This thread should have been rejected !");
90-
Thread.sleep(1000000);
91-
return null;
92-
}
82+
WORKER_THREAD_POOL.submit((Callable<String>) () -> {
83+
Thread.sleep(1000000);
84+
return null;
9385
});
9486
} catch (RejectedExecutionException ex) {
9587
//

0 commit comments

Comments
 (0)