use of com.karumi.rosie.testutils.FakeTaskScheduler in project Rosie by Karumi.
the class UseCaseHandlerTest method shouldNotifyErrorHandlerWhenUseCaseOnErrorCallbackDoesNotExist.
@Test
public void shouldNotifyErrorHandlerWhenUseCaseOnErrorCallbackDoesNotExist() {
FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
ErrorUseCase errorUseCase = new ErrorUseCase();
ErrorHandler errorHandler = mock(ErrorHandler.class);
UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
UseCaseCall useCaseCall = new UseCaseCall(errorUseCase, useCaseHandler);
useCaseCall.useCaseName("customError").onError(specificErrorCallback).execute();
verify(errorHandler).notifyError(any(Error.class), eq(specificErrorCallback));
}
use of com.karumi.rosie.testutils.FakeTaskScheduler in project Rosie by Karumi.
the class UseCaseHandlerTest method shouldCallOnErrorCallbackWhenUseCaseThrowAnUnhandledException.
@Test
public void shouldCallOnErrorCallbackWhenUseCaseThrowAnUnhandledException() {
FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
ErrorUseCase errorUseCase = new ErrorUseCase();
ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
OnErrorCallback errorCallback = spy(onErrorCallback);
UseCaseCall useCaseCall = new UseCaseCall(errorUseCase, useCaseHandler);
useCaseCall.useCaseName("launchException").onError(errorCallback).execute();
verify(errorCallback).onError(any(Error.class));
}
use of com.karumi.rosie.testutils.FakeTaskScheduler in project Rosie by Karumi.
the class UseCaseHandlerTest method shouldThrowExceptionIfUseCaseNotifiesSuccessButThereIsNoOnSuccessCallback.
@Test
public void shouldThrowExceptionIfUseCaseNotifiesSuccessButThereIsNoOnSuccessCallback() {
FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
SuccessUseCase successUseCase = new SuccessUseCase();
ErrorHandler errorHandler = mock(ErrorHandler.class);
UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
UseCaseCall useCaseCall = new UseCaseCall(successUseCase, useCaseHandler);
useCaseCall.execute();
verify(errorHandler).notifyException(any(IllegalStateException.class), eq((OnErrorCallback) null));
}
use of com.karumi.rosie.testutils.FakeTaskScheduler in project Rosie by Karumi.
the class UseCaseHandlerTest method completeCallbackShouldBeCalledWithSuccessArgs.
@Test
public void completeCallbackShouldBeCalledWithSuccessArgs() {
FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
AnyUseCase anyUseCase = new AnyUseCase();
AnyOnSuccess onSuccessCallback = new AnyOnSuccess();
ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
UseCaseCall useCaseCall = new UseCaseCall(anyUseCase, useCaseHandler);
useCaseCall.useCaseName("anyExecution").onSuccess(onSuccessCallback).execute();
assertEquals(ANY_RETURN_VALUE, onSuccessCallback.getValue());
}
use of com.karumi.rosie.testutils.FakeTaskScheduler in project Rosie by Karumi.
the class UseCaseHandlerTest method shouldSupportNullUseCaseParams.
@Test
public void shouldSupportNullUseCaseParams() {
FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
AnyUseCase useCase = new AnyUseCase();
ErrorHandler errorHandler = mock(ErrorHandler.class);
UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
AnyOnSuccess onSuccessCallback = new AnyOnSuccess();
UseCaseCall useCaseCall = new UseCaseCall(useCase, useCaseHandler);
useCaseCall.args(null, ANY_INT_PARAM).onSuccess(onSuccessCallback).execute();
assertEquals(ANY_INT_PARAM, onSuccessCallback.getValue());
}
Aggregations