Search in sources :

Example 6 with ErrorHandler

use of com.karumi.rosie.domain.usecase.error.ErrorHandler 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());
}
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 7 with ErrorHandler

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

the class UseCaseHandlerTest method testExecuteWithArgs.

@Test
public void testExecuteWithArgs() throws Exception {
    TaskScheduler taskScheduler = mock(TaskScheduler.class);
    AnyUseCase anyUseCase = new AnyUseCase();
    ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
    UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
    String anyArg1 = ANY_PARAM1;
    int anyArg2 = ANY_PARAM2;
    UseCaseCall useCaseCall = new UseCaseCall(anyUseCase, useCaseHandler);
    useCaseCall.args(anyArg1, anyArg2).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 8 with ErrorHandler

use of com.karumi.rosie.domain.usecase.error.ErrorHandler 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());
}
Also used : ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) FakeTaskScheduler(com.karumi.rosie.testutils.FakeTaskScheduler) Test(org.junit.Test)

Example 9 with ErrorHandler

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

the class UseCaseHandlerTest method shouldCallErrorHandlerWhenUseCaseInvokeAnError.

@Test
public void shouldCallErrorHandlerWhenUseCaseInvokeAnError() {
    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").execute();
    verify(errorHandler).notifyError(any(Error.class), eq((OnErrorCallback) null));
}
Also used : OnErrorCallback(com.karumi.rosie.domain.usecase.error.OnErrorCallback) ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) FakeTaskScheduler(com.karumi.rosie.testutils.FakeTaskScheduler) NetworkError(com.karumi.rosie.doubles.NetworkError) Test(org.junit.Test)

Example 10 with ErrorHandler

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

the class UseCaseHandlerTest method onSuccessCallbackShouldBeCalledWithSuccessArgs.

@Test
public void onSuccessCallbackShouldBeCalledWithSuccessArgs() {
    FakeTaskScheduler taskScheduler = new FakeTaskScheduler();
    EmptyResponseUseCase anyUseCase = new EmptyResponseUseCase();
    EmptyOnSuccess onSuccessCallback = new EmptyOnSuccess();
    ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
    UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
    UseCaseCall useCaseCall = new UseCaseCall(anyUseCase, useCaseHandler);
    useCaseCall.onSuccess(onSuccessCallback).execute();
    assertTrue(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)

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