@Test public void withRunningStackTest() throws InterruptedException, ExecutionException { SettableListenableFuture<Object> slf = new SettableListenableFuture<>(); slf.setRunningThread(Thread.currentThread()); CancelDebuggingListenableFuture<Object> debugFuture = new CancelDebuggingListenableFuture<>(slf); assertTrue(debugFuture.cancel(false)); try { debugFuture.get(); fail("Exception should have thrown"); } catch (CancellationException e) { // expected assertNotNull(e.getCause()); assertTrue(e.getCause() instanceof FutureProcessingStack); assertEquals(this.getClass().getName(), e.getCause().getStackTrace()[3].getClassName()); } } }
@Test public void notStartedTest() throws InterruptedException, ExecutionException { SettableListenableFuture<Object> slf = new SettableListenableFuture<>(); CancelDebuggingListenableFuture<Object> debugFuture = new CancelDebuggingListenableFuture<>(slf); assertTrue(debugFuture.cancel(false)); try { debugFuture.get(); fail("Exception should have thrown"); } catch (CancellationException e) { // expected assertNull(e.getCause()); } }