@Test public void testListenerFailure() throws Exception { @SuppressWarnings("unchecked") Promise<Void> p1 = createStrictMock(Promise.class); @SuppressWarnings("unchecked") Promise<Void> p2 = createStrictMock(Promise.class); @SuppressWarnings("unchecked") PromiseNotifier<Void, Future<Void>> notifier = new PromiseNotifier<Void, Future<Void>>(p1, p2); @SuppressWarnings("unchecked") Future<Void> future = createStrictMock(Future.class); Throwable t = createStrictMock(Throwable.class); expect(future.isSuccess()).andReturn(false); expect(future.cause()).andReturn(t); expect(p1.setFailure(t)).andReturn(p1); expect(p2.setFailure(t)).andReturn(p2); replay(p1, p2, future); notifier.operationComplete(future); verify(p1, p2); }
@Override public void operationComplete(F future) throws Exception { if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { p.setSuccess(result); } return; } Throwable cause = future.cause(); for (Promise<? super V> p: promises) { p.setFailure(cause); } }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { p.setSuccess(result); } return; } Throwable cause = future.cause(); for (Promise<? super V> p: promises) { p.setFailure(cause); } } }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { p.setSuccess(result); } return; } Throwable cause = future.cause(); for (Promise<? super V> p: promises) { p.setFailure(cause); } } @SafeVarargs  PromiseNotifier(Promise<? super V>... promises); }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { p.setSuccess(result); } return; } Throwable cause = future.cause(); for (Promise<? super V> p: promises) { p.setFailure(cause); } } @SafeVarargs  PromiseNotifier(Promise<? super V>... promises); @Override void operationComplete(F future); }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { p.setSuccess(result); } return; } Throwable cause = future.cause(); for (Promise<? super V> p: promises) { p.setFailure(cause); } } @SafeVarargs  PromiseNotifier(Promise<? super V>... promises); @Override void operationComplete(F future);  }