Skip to content

Commit

Permalink
Merge pull request #7 from spotify/krka/tests
Browse files Browse the repository at this point in the history
Add more tests
  • Loading branch information
spkrka committed Feb 23, 2015
2 parents 080f96e + e3ab9c0 commit aaf3608
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/java/com/spotify/futures/AsyncRetrierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ public void testImmediateSuccess() throws Exception {
assertEquals("direct success", s);
}

@Test
public void testSupplierThrows() throws Exception {
reset(fun);
when(fun.get())
.thenThrow(RuntimeException.class)
.thenReturn(immediateFuture("success"));

ListenableFuture<String> retry = retrier.retry(fun, 5, 100);

executorService.tick(99, MILLISECONDS);
assertFalse(retry.isDone());

executorService.tick(1, MILLISECONDS);
assertTrue(retry.isDone());

String s = getUninterruptibly(retry);

assertEquals("success", s);
}

@Test
public void testRetryFailing() throws Exception {
ListenableFuture<String> retry = retrier.retry(fun, 1, 0);
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/spotify/futures/FuturesExtraTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.spotify.futures;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
Expand Down Expand Up @@ -263,6 +265,30 @@ public void validate(Integer value) throws Exception {
}
}

@Test
public void testSyncTransform() throws Exception {
ListenableFuture<String> future = Futures.immediateFuture("a");
assertEquals("aa", FuturesExtra.syncTransform(future,
new Function<String, String>() {
@Override
public String apply(String s) {
return s + s;
}
}).get());
}

@Test
public void testAsyncTransform() throws Exception {
ListenableFuture<String> future = Futures.immediateFuture("a");
assertEquals("aa", FuturesExtra.asyncTransform(future,
new AsyncFunction<String, String>() {
@Override
public ListenableFuture<String> apply(String s) {
return Futures.immediateFuture(s + s);
}
}).get());
}

@Test
public void testSyncTransform2() throws Exception {
ListenableFuture<String> futureA = Futures.immediateFuture("a");
Expand Down

0 comments on commit aaf3608

Please sign in to comment.