AsyncBroker { public boolean takeWithException(K key, Throwable throwable) { DefaultNoticeableFuture<V> defaultNoticeableFuture = _defaultNoticeableFutures.remove(key); if (defaultNoticeableFuture == null) { return false; } defaultNoticeableFuture.setException(throwable); return true; }  Map<K, NoticeableFuture<V>> getOpenBids(); NoticeableFuture<V> post(K key); NoticeableFuture<V> post(K key, boolean[] newMarker); NoticeableFuture<V> take(K key); boolean takeWithException(K key, Throwable throwable); boolean takeWithResult(K key, V result);  }
@Test public void testTakeWithException() throws Exception { AsyncBroker<String, String> asyncBroker = new AsyncBroker<>(); Map<String, DefaultNoticeableFuture<String>> defaultNoticeableFutures = ReflectionTestUtil.getFieldValue( asyncBroker, "_defaultNoticeableFutures"); Assert.assertTrue( defaultNoticeableFutures.toString(), defaultNoticeableFutures.isEmpty()); Exception exception = new Exception(); Assert.assertFalse(asyncBroker.takeWithException(_KEY, exception)); NoticeableFuture<String> noticeableFuture = asyncBroker.post(_KEY); Assert.assertEquals( defaultNoticeableFutures.toString(), 1, defaultNoticeableFutures.size()); Assert.assertSame(noticeableFuture, defaultNoticeableFutures.get(_KEY)); Assert.assertTrue(asyncBroker.takeWithException(_KEY, exception)); try { noticeableFuture.get(); Assert.fail(); } catch (ExecutionException executionException) { Assert.assertSame(exception, executionException.getCause()); } Assert.assertTrue( defaultNoticeableFutures.toString(), defaultNoticeableFutures.isEmpty()); Assert.assertFalse(asyncBroker.takeWithException(_KEY, exception)); }