PushUseCase { public void execute(final Callback callback) { if (mPushController.isPushInProgress()) { callback.onPushInProgressError(); return; } mPushController.changePushInProgress(true); SurveyChecker.launchQuarantineChecker(); mPushController.push(new IPushController.IPushControllerCallback() { @Override public void onComplete() { System.out.println("PusUseCase Complete"); mPushController.changePushInProgress(false); callback.onComplete(); } @Override public void onError(Throwable throwable) { System.out.println("PusUseCase error"); if (throwable instanceof NetworkException) { mPushController.changePushInProgress(false); callback.onNetworkError(); } else if (throwable instanceof ConversionException) { mPushController.changePushInProgress(false); callback.onConversionError(); } else if (throwable instanceof SurveysToPushNotFoundException) { mPushController.changePushInProgress(false); callback.onSurveysNotFoundError(); } else if (throwable instanceof PushReportException){ mPushController.changePushInProgress(false); callback.onPushError(); } else { mPushController.changePushInProgress(false); callback.onPushError(); } } @Override public void onInformativeError(Throwable throwable) { callback.onInformativeError(throwable.getMessage()); } }); } PushUseCase(IPushController pushController); void execute(final Callback callback);  }
@Test public void should_invoke_in_progress_error_callback_when_is_in_progress() throws Exception { givenThereIsAInProgressPushController(); PushUseCase pushUseCase = new PushUseCase(mPushController); pushUseCase.execute(new PushUseCase.Callback() { @Override public void onComplete() { callbackInvoked(false); } @Override public void onPushError() { callbackInvoked(false); } @Override public void onPushInProgressError() { callbackInvoked(true); } @Override public void onSurveysNotFoundError() { callbackInvoked(false); } @Override public void onInformativeError(String message) { callbackInvoked(false); } @Override public void onConversionError() { callbackInvoked(false); } @Override public void onNetworkError() { callbackInvoked(false); } }); lock.await(100, TimeUnit.MILLISECONDS); assertThat(invokedInProgressCallback, is(true)); }