Skip to content

Commit 0bb0966

Browse files
author
Grzegorz Piwowarek
committed
Refactor CompletableFutureTest
1 parent 5195a43 commit 0bb0966

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

‎core-java-8/src/test/java/com/baeldung/completablefuture/CompletableFutureTest.java‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package com.baeldung.completablefuture;
22

3+
import org.junit.Test;
4+
35
import java.util.concurrent.CompletableFuture;
46
import java.util.concurrent.ExecutionException;
57
import java.util.concurrent.Executors;
68
import java.util.concurrent.Future;
79
import java.util.stream.Collectors;
810
import java.util.stream.Stream;
911

10-
import org.junit.Test;
11-
1212
import static org.junit.Assert.assertEquals;
1313
import static org.junit.Assert.assertTrue;
1414

1515
public class CompletableFutureTest {
1616

1717
@Test
18-
public void whenRunningCompletableFutureAsyncronously_thenGetMethodWaitsForResult() throws InterruptedException, ExecutionException {
18+
public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResult() throws InterruptedException, ExecutionException {
1919

2020
Future<String> completableFuture = calculateAsync();
2121

@@ -144,7 +144,7 @@ public void whenFutureCombinedWithAllOfCompletes_thenAllFuturesAreDone() throws
144144
}
145145

146146
@Test
147-
public void whenFutureThrows_thenHandleMethodRecievesException() throws ExecutionException, InterruptedException {
147+
public void whenFutureThrows_thenHandleMethodReceivesException() throws ExecutionException, InterruptedException {
148148

149149
String name = null;
150150

@@ -155,13 +155,7 @@ public void whenFutureThrows_thenHandleMethodRecievesException() throws Executio
155155
throw new RuntimeException("Computation error!");
156156
}
157157
return "Hello, " + name;
158-
}).handle((s, t) -> {
159-
if (s != null) {
160-
return s;
161-
} else {
162-
return "Hello, Stranger!";
163-
}
164-
});
158+
}).handle((s, t) -> s != null ? s : "Hello, Stranger!");
165159

166160
assertEquals("Hello, Stranger!", completableFuture.get());
167161

0 commit comments

Comments
 (0)