11package com .baeldung .vavr .future ;
22
3- import static org .junit .Assert .assertEquals ;
4- import static org .junit .Assert .assertFalse ;
5- import static org .junit .Assert .assertTrue ;
3+ import static org .assertj .core .api .Assertions .assertThat ;
64
75import java .util .concurrent .CompletableFuture ;
86import java .util .concurrent .ExecutionException ;
@@ -23,7 +21,7 @@ public void whenAppendData_thenCorrect1() {
2321 Future <String > resultFuture = Future .of (() -> Util .appendData (initialValue ));
2422 String result = resultFuture .get ();
2523
26- assertEquals ( "Welcome to Baeldung!" , result );
24+ assertThat ( result ). isEqualTo ( "Welcome to Baeldung!" );
2725 }
2826
2927 @ Test
@@ -35,7 +33,7 @@ public void whenAppendData_thenCorrect2() {
3533 Try <String > futureTry = futureOption .get ();
3634 String result = futureTry .get ();
3735
38- assertEquals ( "Welcome to Baeldung!" , result );
36+ assertThat ( result ). isEqualTo ( "Welcome to Baeldung!" );
3937 }
4038
4139 @ Test
@@ -46,7 +44,7 @@ public void whenAppendData_thenSuccess() {
4644 .onFailure (finalResult -> System .out .println ("Failed - Result: " + finalResult ));
4745 String result = resultFuture .get ();
4846
49- assertEquals ( "Welcome to Baeldung!" , result );
47+ assertThat ( result ). isEqualTo ( "Welcome to Baeldung!" );
5048 }
5149
5250 @ Test
@@ -57,7 +55,7 @@ public void whenChainingCallbacks_thenCorrect() {
5755 .andThen (finalResult -> System .out .println ("Completed - 2: " + finalResult ));
5856 String result = resultFuture .get ();
5957
60- assertEquals ( "Welcome to Baeldung!" , result );
58+ assertThat ( result ). isEqualTo ( "Welcome to Baeldung!" );
6159 }
6260
6361 @ Test
@@ -67,7 +65,7 @@ public void whenCallAwait_thenCorrect() {
6765 resultFuture = resultFuture .await ();
6866 String result = resultFuture .get ();
6967
70- assertEquals ( "Welcome to Baeldung!" , result );
68+ assertThat ( result ). isEqualTo ( "Welcome to Baeldung!" );
7169 }
7270
7371 @ Test
@@ -76,7 +74,7 @@ public void whenDivideByZero_thenGetThrowable1() {
7674 Future <Throwable > throwableFuture = resultFuture .failed ();
7775 Throwable throwable = throwableFuture .get ();
7876
79- assertEquals ( "/ by zero" , throwable . getMessage () );
77+ assertThat ( throwable . getMessage ()). isEqualTo ( "/ by zero" );
8078 }
8179
8280 @ Test
@@ -86,17 +84,17 @@ public void whenDivideByZero_thenGetThrowable2() {
8684 Option <Throwable > throwableOption = resultFuture .getCause ();
8785 Throwable throwable = throwableOption .get ();
8886
89- assertEquals ( "/ by zero" , throwable . getMessage () );
87+ assertThat ( throwable . getMessage ()). isEqualTo ( "/ by zero" );
9088 }
9189
9290 @ Test
9391 public void whenDivideByZero_thenCorrect () throws InterruptedException {
9492 Future <Integer > resultFuture = Future .of (() -> Util .divideByZero (10 ));
9593 resultFuture .await ();
9694
97- assertTrue (resultFuture .isCompleted ());
98- assertFalse (resultFuture .isSuccess ());
99- assertTrue (resultFuture .isFailure ());
95+ assertThat (resultFuture .isCompleted ()). isTrue ( );
96+ assertThat (resultFuture .isSuccess ()). isFalse ( );
97+ assertThat (resultFuture .isFailure ()). isTrue ( );
10098 }
10199
102100 @ Test
@@ -105,7 +103,7 @@ public void whenAppendData_thenFutureNotEmpty() {
105103 Future <String > resultFuture = Future .of (() -> Util .appendData (initialValue ));
106104 resultFuture .await ();
107105
108- assertFalse (resultFuture .isEmpty ());
106+ assertThat (resultFuture .isEmpty ()). isFalse ( );
109107 }
110108
111109 @ Test
@@ -114,7 +112,7 @@ public void whenCallZip_thenCorrect() {
114112 .zip (Future .of (() -> new Integer (5 )));
115113 future .await ();
116114
117- assertEquals ( Tuple .of ("John" , new Integer (5 )), future . get ( ));
115+ assertThat ( future . get ()). isEqualTo ( Tuple .of ("John" , new Integer (5 )));
118116 }
119117
120118 @ Test
@@ -123,7 +121,7 @@ public void whenAppendData_thenFutureNotEmptyd() throws InterruptedException, Ex
123121 Future <String > resultFuture = Future .of (() -> Util .appendData (initialValue ));
124122 CompletableFuture <String > convertedFuture = resultFuture .toCompletableFuture ();
125123
126- assertEquals ( "Welcome to Baeldung!" , convertedFuture . get () );
124+ assertThat ( convertedFuture . get ()). isEqualTo ( "Welcome to Baeldung!" );
127125 }
128126
129127 @ Test
@@ -132,6 +130,6 @@ public void whenCallMap_thenCorrect() {
132130 .map (a -> "Hello " + a );
133131 futureResult .await ();
134132
135- assertEquals ( "Hello from Baeldung" , futureResult . get () );
133+ assertThat ( futureResult . get ()). isEqualTo ( "Hello from Baeldung" );
136134 }
137135}
0 commit comments