Skip to content

Commit 2b5a125

Browse files
Ahmed Tawilapivovarit
authored andcommitted
BAEL-1080 Introduction to Future in Vavr (eugenp#3372)
* Add missing features * Add missing features
1 parent c8cf103 commit 2b5a125

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public void whenAppendData_thenSuccess() {
5858
assertThat(result)
5959
.isEqualTo(HELLO);
6060
}
61+
62+
@Test
63+
public void whenTransform_thenCorrect() {
64+
Future<Object> future = Future.of(() -> 5)
65+
.transformValue(result -> Try.of(() -> HELLO + result.get()));
66+
67+
assertThat(future.get()).isEqualTo(HELLO + 5);
68+
}
6169

6270
@Test
6371
public void whenChainingCallbacks_thenCorrect() {
@@ -139,6 +147,14 @@ public void whenCallMap_thenCorrect() {
139147
assertThat(futureResult.get())
140148
.isEqualTo("Hello from Baeldung");
141149
}
150+
151+
@Test
152+
public void whenCallFlatMap_thenCorrect() {
153+
Future<Object> futureMap = Future.of(() -> 1)
154+
.flatMap((i) -> Future.of(() -> "Hello: " + i));
155+
156+
assertThat(futureMap.get()).isEqualTo("Hello: 1");
157+
}
142158

143159
@Test
144160
public void whenFutureFails_thenGetErrorMessage() {

0 commit comments

Comments
 (0)