Search in sources :

Example 6 with FakeTaskScheduler

use of com.karumi.rosie.testutils.FakeTaskScheduler 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 7 with FakeTaskScheduler

use of com.karumi.rosie.testutils.FakeTaskScheduler 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 8 with FakeTaskScheduler

use of com.karumi.rosie.testutils.FakeTaskScheduler 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 9 with FakeTaskScheduler

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

Example 10 with FakeTaskScheduler

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

Aggregations

ErrorHandler (com.karumi.rosie.domain.usecase.error.ErrorHandler)12 FakeTaskScheduler (com.karumi.rosie.testutils.FakeTaskScheduler)12 Test (org.junit.Test)12 OnErrorCallback (com.karumi.rosie.domain.usecase.error.OnErrorCallback)6 FakeCallbackScheduler (com.karumi.rosie.doubles.FakeCallbackScheduler)6 NetworkError (com.karumi.rosie.doubles.NetworkError)4 OnSuccessCallback (com.karumi.rosie.domain.usecase.callback.OnSuccessCallback)1