BAEL-1080 Introduction to Future in Vavr (#3372)

* Add missing features

* Add missing features
This commit is contained in:
Ahmed Tawila 2018-01-09 13:31:45 +02:00 committed by Grzegorz Piwowarek
parent c8cf103fbc
commit 2b5a125440
1 changed files with 16 additions and 0 deletions

View File

@ -59,6 +59,14 @@ public class FutureTest {
.isEqualTo(HELLO); .isEqualTo(HELLO);
} }
@Test
public void whenTransform_thenCorrect() {
Future<Object> future = Future.of(() -> 5)
.transformValue(result -> Try.of(() -> HELLO + result.get()));
assertThat(future.get()).isEqualTo(HELLO + 5);
}
@Test @Test
public void whenChainingCallbacks_thenCorrect() { public void whenChainingCallbacks_thenCorrect() {
Future.of(() -> HELLO) Future.of(() -> HELLO)
@ -140,6 +148,14 @@ public class FutureTest {
.isEqualTo("Hello from Baeldung"); .isEqualTo("Hello from Baeldung");
} }
@Test
public void whenCallFlatMap_thenCorrect() {
Future<Object> futureMap = Future.of(() -> 1)
.flatMap((i) -> Future.of(() -> "Hello: " + i));
assertThat(futureMap.get()).isEqualTo("Hello: 1");
}
@Test @Test
public void whenFutureFails_thenGetErrorMessage() { public void whenFutureFails_thenGetErrorMessage() {
Future<String> future = Future.of(() -> "Hello".substring(-1)) Future<String> future = Future.of(() -> "Hello".substring(-1))