Search in sources :

Example 1 with FakeCallbackScheduler

use of com.karumi.rosie.doubles.FakeCallbackScheduler in project Rosie by Karumi.

the class UseCaseHandlerTest method testExecuteWithMethodName.

@Test
public void testExecuteWithMethodName() 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);
    useCaseCall.useCaseName(ANY_EXECUTION_NAME).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 2 with FakeCallbackScheduler

use of com.karumi.rosie.doubles.FakeCallbackScheduler in project Rosie by Karumi.

the class UseCaseHandlerTest method testExecuteFailNotAnyUseCase.

@Test
public void testExecuteFailNotAnyUseCase() throws Exception {
    TaskScheduler taskScheduler = mock(TaskScheduler.class);
    NoUseCase noUseCase = new NoUseCase();
    UseCaseParams emptyUseCaseParms = givenEmptyUseCaseParms();
    ErrorHandler errorHandler = new ErrorHandler(new FakeCallbackScheduler());
    UseCaseHandler useCaseHandler = new UseCaseHandler(taskScheduler, errorHandler);
    boolean exception = false;
    try {
        useCaseHandler.execute(noUseCase, emptyUseCaseParms);
    } catch (IllegalArgumentException e) {
        exception = true;
    }
    assertTrue(exception);
    verify(taskScheduler, never()).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 3 with FakeCallbackScheduler

use of com.karumi.rosie.doubles.FakeCallbackScheduler 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));
}
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) FakeCallbackScheduler(com.karumi.rosie.doubles.FakeCallbackScheduler) Test(org.junit.Test)

Example 4 with FakeCallbackScheduler

use of com.karumi.rosie.doubles.FakeCallbackScheduler 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 5 with FakeCallbackScheduler

use of com.karumi.rosie.doubles.FakeCallbackScheduler 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)

Aggregations

ErrorHandler (com.karumi.rosie.domain.usecase.error.ErrorHandler)13 FakeCallbackScheduler (com.karumi.rosie.doubles.FakeCallbackScheduler)13 FakeTaskScheduler (com.karumi.rosie.testutils.FakeTaskScheduler)13 Test (org.junit.Test)13 OnErrorCallback (com.karumi.rosie.domain.usecase.error.OnErrorCallback)2 NetworkError (com.karumi.rosie.doubles.NetworkError)2