use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.
the class UseCaseHandlerTest method shouldCallErrorOnErrorWhenUseCaseInvokeAnError.
@Test
public void shouldCallErrorOnErrorWhenUseCaseInvokeAnError() {
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("customError").onError(errorCallback).execute();
verify(errorCallback).onError(any(Error.class));
}
use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.
the class UseCaseHandlerTest method shouldCallErrorHandlerErrorWhenUseCaseThrowsAnException.
@Test
public void shouldCallErrorHandlerErrorWhenUseCaseThrowsAnException() {
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("launchException").execute();
verify(errorHandler).notifyException(any(Exception.class), eq((OnErrorCallback) null));
}
use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.
the class UseCaseHandlerTest method testExecuteFailsWithWrongMethodName.
@Test
public void testExecuteFailsWithWrongMethodName() throws Exception {
TaskScheduler taskScheduler = mock(TaskScheduler.class);
AnyUseCase anyUseCase = new AnyUseCase();
ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
UseCaseCall useCaseCall = new UseCaseCall(anyUseCase, useCaseHandler);
boolean error = false;
try {
useCaseCall.useCaseName(NO_EXIST_METHOD_NAME).execute();
} catch (IllegalArgumentException e) {
error = true;
}
assertTrue(error);
verify(taskScheduler, never()).execute(any(UseCaseWrapper.class));
}
use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.
the class UseCaseHandlerTest method testExecuteAmbigous.
@Test
public void testExecuteAmbigous() throws Exception {
TaskScheduler taskScheduler = mock(TaskScheduler.class);
AmbiguousUseCase ambigousUseCase = new AmbiguousUseCase();
ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
UseCaseCall useCaseCall = new UseCaseCall(ambigousUseCase, useCaseHandler);
boolean exception = false;
try {
useCaseCall.args(ANY_PARAM1, ANY_PARAM2).execute();
} catch (IllegalArgumentException e) {
exception = true;
}
assertTrue(exception);
verify(taskScheduler, never()).execute(any(UseCaseWrapper.class));
}
use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.
the class UseCaseHandlerTest method shouldThrowExceptionIfTheOnSuccessCallbackHasNoMethodsWithSuccessAnnotations.
@Test
public void shouldThrowExceptionIfTheOnSuccessCallbackHasNoMethodsWithSuccessAnnotations() {
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.onSuccess(new OnSuccessCallback() {
}).execute();
verify(errorHandler).notifyException(any(IllegalStateException.class), eq((OnErrorCallback) null));
}
Aggregations