Search in sources :

Example 16 with ErrorHandler

use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.

the class UseCaseHandlerTest method testExecuteAnyObject.

@Test
public void testExecuteAnyObject() throws Exception {
    TaskScheduler taskScheduler = mock(TaskScheduler.class);
    EmptyUseCase anyUseCase = new EmptyUseCase();
    UseCaseParams emptyParams = givenEmptyUseCaseParms();
    ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
    UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
    useCaseHandler.execute(anyUseCase, emptyParams);
    verify(taskScheduler, only()).execute(any(UseCaseWrapper.class));
}
Also used : ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) FakeTaskScheduler(com.karumi.rosie.testutils.FakeTaskScheduler) FakeCallbackScheduler(com.karumi.rosie.doubles.FakeCallbackScheduler) Test(org.junit.Test)

Example 17 with ErrorHandler

use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.

the class UseCaseHandlerTest method onSuccessCallbackShouldBeCalledWithSuccessArgsAndDowncastingResponse.

@Test
public void onSuccessCallbackShouldBeCalledWithSuccessArgsAndDowncastingResponse() {
    FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
    AnyUseCase anyUseCase = new AnyUseCase();
    AnyOnSuccessWithDowncast onSuccessCallback = new AnyOnSuccessWithDowncast();
    ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
    UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
    UseCaseCall useCaseCall = new UseCaseCall(anyUseCase, useCaseHandler);
    useCaseCall.useCaseName("downcastResponse").onSuccess(onSuccessCallback).execute();
    assertNotNull(onSuccessCallback.getValue());
}
Also used : ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) FakeTaskScheduler(com.karumi.rosie.testutils.FakeTaskScheduler) FakeCallbackScheduler(com.karumi.rosie.doubles.FakeCallbackScheduler) Test(org.junit.Test)

Example 18 with ErrorHandler

use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.

the class UseCaseHandlerTest method completeCallbackShouldNotBeExecutedWhenNotMatchArgs.

@Test
public void completeCallbackShouldNotBeExecutedWhenNotMatchArgs() {
    FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
    AnyUseCase anyUseCase = new AnyUseCase();
    EmptyOnSuccess onSuccessCallback = new EmptyOnSuccess();
    ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
    UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
    UseCaseCall useCaseCall = new UseCaseCall(anyUseCase, useCaseHandler);
    useCaseCall.useCaseName("anyExecution").onSuccess(onSuccessCallback).execute();
    assertFalse(onSuccessCallback.isSuccess());
}
Also used : ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) FakeTaskScheduler(com.karumi.rosie.testutils.FakeTaskScheduler) FakeCallbackScheduler(com.karumi.rosie.doubles.FakeCallbackScheduler) Test(org.junit.Test)

Example 19 with ErrorHandler

use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.

the class UseCaseHandlerTest method testExecuteNoAmbigous.

@Test
public void testExecuteNoAmbigous() 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);
    useCaseCall.args(ANY_PARAM1, ANY_PARAM2).useCaseName("method1").execute();
    verify(taskScheduler, only()).execute(any(UseCaseWrapper.class));
}
Also used : ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) FakeTaskScheduler(com.karumi.rosie.testutils.FakeTaskScheduler) FakeCallbackScheduler(com.karumi.rosie.doubles.FakeCallbackScheduler) Test(org.junit.Test)

Example 20 with ErrorHandler

use of com.karumi.rosie.domain.usecase.error.ErrorHandler in project Rosie by Karumi.

the class UseCaseWrapperTest method shouldNotifyErrorNotifiedFromTheUseCase.

@Test
public void shouldNotifyErrorNotifiedFromTheUseCase() {
    AnyUseCase anyUseCase = new AnyUseCase();
    anyUseCase.setErrorToNotify(new Error());
    UseCaseParams argsParams = givenUseCaseParamsWithArgs(ANY_FIRST_ARG, ANY_SECOND_ARG);
    ErrorHandler errorHandler = mock(ErrorHandler.class);
    UseCaseWrapper useCaseWrapper = new UseCaseWrapper(anyUseCase, argsParams, errorHandler);
    useCaseWrapper.execute();
    verify(errorHandler).notifyException(any(ErrorNotHandledException.class), eq((OnErrorCallback) null));
}
Also used : OnErrorCallback(com.karumi.rosie.domain.usecase.error.OnErrorCallback) ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) ErrorNotHandledException(com.karumi.rosie.domain.usecase.error.ErrorNotHandledException) Test(org.junit.Test)

Aggregations

ErrorHandler (com.karumi.rosie.domain.usecase.error.ErrorHandler)20 Test (org.junit.Test)20 FakeTaskScheduler (com.karumi.rosie.testutils.FakeTaskScheduler)19 FakeCallbackScheduler (com.karumi.rosie.doubles.FakeCallbackScheduler)13 OnErrorCallback (com.karumi.rosie.domain.usecase.error.OnErrorCallback)7 NetworkError (com.karumi.rosie.doubles.NetworkError)4 OnSuccessCallback (com.karumi.rosie.domain.usecase.callback.OnSuccessCallback)1 ErrorNotHandledException (com.karumi.rosie.domain.usecase.error.ErrorNotHandledException)1