NoticeableFutureConverter extends FutureConverter<T, V> implements NoticeableFuture<T> { @Override public T get() throws ExecutionException, InterruptedException { return _defaultNoticeableFuture.get(); } NoticeableFutureConverter(NoticeableFuture<V> noticeableFuture); @Override boolean addFutureListener(FutureListener<T> futureListener); @Override T get(); @Override T get(long timeout, TimeUnit timeUnit); @Override boolean removeFutureListener(FutureListener<T> futureListener);  }
@Test public void testCancelInner() throws Exception { NoticeableFuture<Object> noticeableFutureConverter = new NopNoticeableFutureConverter(_defaultNoticeableFuture); Assert.assertFalse(noticeableFutureConverter.isCancelled()); Assert.assertFalse(noticeableFutureConverter.isDone()); _defaultNoticeableFuture.cancel(true); Assert.assertTrue(_defaultNoticeableFuture.isCancelled()); Assert.assertTrue(_defaultNoticeableFuture.isDone()); Assert.assertTrue(noticeableFutureConverter.isCancelled()); Assert.assertTrue(noticeableFutureConverter.isDone()); try { noticeableFutureConverter.get(); Assert.fail(); } catch (CancellationException cancellationException) { } try { noticeableFutureConverter.get(1, TimeUnit.SECONDS); Assert.fail(); } catch (CancellationException cancellationException) { } }
@Test public void testCancelOutter() throws Exception { NoticeableFuture<Object> noticeableFutureConverter = new NopNoticeableFutureConverter(_defaultNoticeableFuture); Assert.assertFalse(noticeableFutureConverter.isCancelled()); Assert.assertFalse(noticeableFutureConverter.isDone()); noticeableFutureConverter.cancel(true); Assert.assertTrue(_defaultNoticeableFuture.isCancelled()); Assert.assertTrue(_defaultNoticeableFuture.isDone()); Assert.assertTrue(noticeableFutureConverter.isCancelled()); Assert.assertTrue(noticeableFutureConverter.isDone()); try { noticeableFutureConverter.get(); Assert.fail(); } catch (CancellationException cancellationException) { } try { noticeableFutureConverter.get(1, TimeUnit.SECONDS); Assert.fail(); } catch (CancellationException cancellationException) { } }
@Test public void testCovertResult() throws Exception { NoticeableFuture<Object> noticeableFutureConverter = new NopNoticeableFutureConverter(_defaultNoticeableFuture); Object result = new Object(); _defaultNoticeableFuture.set(result); Assert.assertSame(result, noticeableFutureConverter.get()); Assert.assertSame( result, noticeableFutureConverter.get(1, TimeUnit.SECONDS)); }
@Test(timeout = 10000) public void testInterruptionException() throws Exception { NoticeableFuture<Object> noticeableFutureConverter = new NopNoticeableFutureConverter(_defaultNoticeableFuture); Thread currentThread = Thread.currentThread(); currentThread.interrupt(); try { noticeableFutureConverter.get(); Assert.fail(); } catch (InterruptedException interruptedException) { } Assert.assertFalse(currentThread.isInterrupted()); currentThread.interrupt(); try { noticeableFutureConverter.get(1, TimeUnit.MILLISECONDS); Assert.fail(); } catch (InterruptedException interruptedException) { } Assert.assertFalse(currentThread.isInterrupted()); }
@Test public void testTimeoutException() throws Exception { NoticeableFuture<Object> noticeableFutureConverter = new NopNoticeableFutureConverter(_defaultNoticeableFuture); try { noticeableFutureConverter.get(1, TimeUnit.MILLISECONDS); Assert.fail(); } catch (TimeoutException timeoutException) { } }