11package com .baeldung .completablefuture ;
22
3+ import org .junit .Test ;
4+
35import java .util .concurrent .CompletableFuture ;
46import java .util .concurrent .ExecutionException ;
57import java .util .concurrent .Executors ;
68import java .util .concurrent .Future ;
79import java .util .stream .Collectors ;
810import java .util .stream .Stream ;
911
10- import org .junit .Test ;
11-
1212import static org .junit .Assert .assertEquals ;
1313import static org .junit .Assert .assertTrue ;
1414
1515public 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