Skip to content

Commit

Permalink
Fix missed coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
spkrka committed Nov 6, 2015
1 parent e88cf3b commit 130302f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/spotify/futures/CompletableFuturesExtra.java
Expand Up @@ -19,8 +19,8 @@
import com.google.common.util.concurrent.ListenableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -196,16 +196,16 @@ public static void checkCompleted(CompletionStage<?> stage) {
* @param stage a completed stage.
* @return the value of the stage if it has one.
* @throws IllegalStateException if the stage is not completed.
* @throws com.google.common.util.concurrent.UncheckedExecutionException if the future has failed
* @throws com.google.common.util.concurrent.UncheckedExecutionException
* if the future has failed with a non-runtime exception, otherwise
* the actual exception
*/
public static <T> T getCompleted(CompletionStage<T> stage) {
CompletableFuture<T> future = stage.toCompletableFuture();
checkCompleted(future);
try {
return future.get();
} catch (InterruptedException e) {
throw Throwables.propagate(e);
} catch (ExecutionException e) {
return future.join();
} catch (CompletionException e) {
throw Throwables.propagate(e.getCause());
}
}
Expand Down
Expand Up @@ -126,6 +126,13 @@ public void testGetCompleted() throws Exception {
assertEquals("hello", CompletableFuturesExtra.getCompleted(future));
}

@Test(expected = IllegalStateException.class)
public void testGetCompletedFails() throws Exception {
final CompletionStage<String> future = new CompletableFuture<String>();
CompletableFuturesExtra.getCompleted(future);
fail();
}

@Test(expected = IllegalArgumentException.class)
public void testDereferenceFailure() throws Exception {
final CompletionStage<Object> future = CompletableFuturesExtra.exceptionallyCompletedFuture(new IllegalArgumentException());
Expand Down

0 comments on commit 130302f

Please sign in to comment.