-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from zalando/feature/exceptionally-compose
Added support for asynchronous fallbacks
- Loading branch information
Showing
5 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/java/org/zalando/fauxpas/ExceptionallyComposeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.zalando.fauxpas; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static java.util.concurrent.CompletableFuture.completedFuture; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.zalando.fauxpas.FauxPas.exceptionallyCompose; | ||
import static org.zalando.fauxpas.FauxPas.partially; | ||
|
||
class ExceptionallyComposeTest { | ||
|
||
@Test | ||
void shouldExceptionallyCompose() { | ||
final CompletableFuture<String> original = new CompletableFuture<>(); | ||
final CompletableFuture<String> unit = exceptionallyCompose(original, partially(e -> | ||
completedFuture("result"))); | ||
|
||
original.completeExceptionally(new RuntimeException()); | ||
|
||
assertThat(unit.join(), is("result")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.zalando.fauxpas; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static java.util.concurrent.CompletableFuture.completedFuture; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.zalando.fauxpas.FauxPas.exceptionallyCompose; | ||
import static org.zalando.fauxpas.FauxPas.handleCompose; | ||
import static org.zalando.fauxpas.FauxPas.partially; | ||
|
||
class HandleComposeTest { | ||
|
||
@Test | ||
void shouldHandleComposeResult() { | ||
final CompletableFuture<String> original = new CompletableFuture<>(); | ||
final CompletableFuture<String> unit = handleCompose(original, (s, throwable) -> | ||
completedFuture("result")); | ||
|
||
original.complete("foo"); | ||
|
||
assertThat(unit.join(), is("result")); | ||
} | ||
|
||
@Test | ||
void shouldHandleComposeException() { | ||
final CompletableFuture<String> original = new CompletableFuture<>(); | ||
final CompletableFuture<String> unit = handleCompose(original, (s, throwable) -> | ||
completedFuture("result")); | ||
|
||
original.completeExceptionally(new RuntimeException()); | ||
|
||
assertThat(unit.join(), is("result")); | ||
} | ||
|
||
} |