Search in sources :

Example 6 with FakeCallbackScheduler

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

Example 7 with FakeCallbackScheduler

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

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

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

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

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