Skip to content

Commit

Permalink
Add unit tests for passing null to addCallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Wright committed Oct 30, 2015
1 parent 22526c0 commit 58a5b51
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/com/spotify/futures/FuturesExtraTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ public void testCallbackForSuccess() throws Exception {
verify(failure, never()).accept(any(Throwable.class));
}

@Test
public void testCallbackForSuccessNullFailure() throws Exception {
final SettableFuture<Integer> future = SettableFuture.create();
final Consumer<Integer> success = mock(Consumer.class);

FuturesExtra.addCallback(future, success, null);

future.set(10);
verify(success).accept(10);
}

@Test
public void testCallbackForFailure() throws Exception {
final SettableFuture<Integer> future = SettableFuture.create();
Expand All @@ -299,6 +310,24 @@ public void testCallbackForFailure() throws Exception {
verify(success, never()).accept(anyInt());
}

@Test
public void testCallbackForFailureNullSuccess() throws Exception {
final SettableFuture<Integer> future = SettableFuture.create();
final Consumer<Throwable> failure = mock(Consumer.class);

FuturesExtra.addCallback(future, null, failure);

final Throwable expected = new RuntimeException("boom");
future.setException(expected);
verify(failure).accept(expected);
}

@Test(expected = NullPointerException.class)
public void testCallbackWithNulls() throws Exception {
final SettableFuture<Integer> future = SettableFuture.create();
FuturesExtra.addCallback(future, null, null);
}

@Test
public void testSuccessCallback() throws Exception {
final SettableFuture<Integer> future = SettableFuture.create();
Expand Down

0 comments on commit 58a5b51

Please sign in to comment.