@Test public void testListenerSuccess() throws Exception { @SuppressWarnings("unchecked") Promise<Void> p1 = mock(Promise.class); @SuppressWarnings("unchecked") Promise<Void> p2 = mock(Promise.class); @SuppressWarnings("unchecked") PromiseNotifier<Void, Future<Void>> notifier = new PromiseNotifier<Void, Future<Void>>(p1, p2); @SuppressWarnings("unchecked") Future<Void> future = mock(Future.class); when(future.isSuccess()).thenReturn(true); when(future.get()).thenReturn(null); when(p1.trySuccess(null)).thenReturn(true); when(p2.trySuccess(null)).thenReturn(true); notifier.operationComplete(future); verify(p1).trySuccess(null); verify(p2).trySuccess(null); }
@Override public void operationComplete(F future) throws Exception { InternalLogger internalLogger = logNotifyFailure ? logger : null; if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.trySuccess(p, result, internalLogger); } } else if (future.isCancelled()) { for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryCancel(p, internalLogger); } } else { Throwable cause = future.cause(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryFailure(p, cause, internalLogger); } } }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { InternalLogger internalLogger = logNotifyFailure ? logger : null; if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.trySuccess(p, result, internalLogger); } } else if (future.isCancelled()) { for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryCancel(p, internalLogger); } } else { Throwable cause = future.cause(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryFailure(p, cause, internalLogger); } } } }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { InternalLogger internalLogger = logNotifyFailure ? logger : null; if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.trySuccess(p, result, internalLogger); } } else if (future.isCancelled()) { for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryCancel(p, internalLogger); } } else { Throwable cause = future.cause(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryFailure(p, cause, internalLogger); } } } @SafeVarargs  PromiseNotifier(Promise<? super V>... promises); @SafeVarargs  PromiseNotifier(boolean logNotifyFailure, Promise<? super V>... promises); }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { InternalLogger internalLogger = logNotifyFailure ? logger : null; if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.trySuccess(p, result, internalLogger); } } else if (future.isCancelled()) { for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryCancel(p, internalLogger); } } else { Throwable cause = future.cause(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryFailure(p, cause, internalLogger); } } } @SafeVarargs  PromiseNotifier(Promise<? super V>... promises); @SafeVarargs  PromiseNotifier(boolean logNotifyFailure, Promise<? super V>... promises); @Override void operationComplete(F future); }
PromiseNotifier implements GenericFutureListener<F> { @Override public void operationComplete(F future) throws Exception { InternalLogger internalLogger = logNotifyFailure ? logger : null; if (future.isSuccess()) { V result = future.get(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.trySuccess(p, result, internalLogger); } } else if (future.isCancelled()) { for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryCancel(p, internalLogger); } } else { Throwable cause = future.cause(); for (Promise<? super V> p: promises) { PromiseNotificationUtil.tryFailure(p, cause, internalLogger); } } } @SafeVarargs  PromiseNotifier(Promise<? super V>... promises); @SafeVarargs  PromiseNotifier(boolean logNotifyFailure, Promise<? super V>... promises); @Override void operationComplete(F future);  }