| 23 | import org.junit.Test; |
| 24 | |
| 25 | public class FutureTest { |
| 26 | |
| 27 | private <T> T get(Future<T> future) throws CheckedFutureException { |
| 28 | return future.get(Duration.ofMillis(1)); |
| 29 | } |
| 30 | |
| 31 | private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); |
| 32 | private final Exception ex = new TestException(); |
| 33 | |
| 34 | @After |
| 35 | public void shutdownScheduler() { |
| 36 | scheduler.shutdown(); |
| 37 | } |
| 38 | |
| 39 | /*** true ***/ |
| 40 | |
| 41 | @Test |
| 42 | public void trueConst() throws CheckedFutureException { |
| 43 | assertEquals(true, get(Future.TRUE)); |
| 44 | } |
| 45 | |
| 46 | /*** false ***/ |
| 47 | |
| 48 | @Test |
| 49 | public void falseConst() throws CheckedFutureException { |
| 50 | assertEquals(false, get(Future.FALSE)); |
| 51 | } |
| 52 | |
| 53 | /*** never ***/ |
| 54 | |
| 55 | @Test |
| 56 | public void never() { |
| 57 | assertTrue(Future.never() instanceof NoFuture); |
| 58 | } |
| 59 | |
| 60 | /*** apply ***/ |
| 61 | |
| 62 | @Test |
| 63 | public void applyValue() throws CheckedFutureException { |
| 64 | Integer value = 1; |
| 65 | Future<Integer> future = Future.apply(() -> value); |
| 66 | assertEquals(value, get(future)); |
| 67 | } |
| 68 | |
| 69 | @Test(expected = ArithmeticException.class) |
| 70 | public void applyException() throws CheckedFutureException { |
| 71 | Future<Integer> future = Future.apply(() -> 1 / 0); |
| 72 | get(future); |
| 73 | } |
| 74 | |
| 75 | /*** flatApply ***/ |
| 76 | |
| 77 | @Test |
| 78 | public void flatApplyValue() throws CheckedFutureException { |
| 79 | Integer value = 1; |
| 80 | Future<Integer> future = Future.flatApply(() -> Future.value(value)); |
| 81 | assertEquals(value, get(future)); |
| 82 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…