Search in sources :

Example 1 with OnErrorCallback

use of com.karumi.rosie.domain.usecase.error.OnErrorCallback 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 2 with OnErrorCallback

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

the class UseCaseHandlerTest method shouldThrowExceptionIfUseCaseNotifiesSuccessButThereIsNoOnSuccessCallback.

@Test
public void shouldThrowExceptionIfUseCaseNotifiesSuccessButThereIsNoOnSuccessCallback() {
    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.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) Test(org.junit.Test)

Example 3 with OnErrorCallback

use of com.karumi.rosie.domain.usecase.error.OnErrorCallback 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 4 with OnErrorCallback

use of com.karumi.rosie.domain.usecase.error.OnErrorCallback 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 5 with OnErrorCallback

use of com.karumi.rosie.domain.usecase.error.OnErrorCallback 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)

Aggregations

OnErrorCallback (com.karumi.rosie.domain.usecase.error.OnErrorCallback)9 ErrorHandler (com.karumi.rosie.domain.usecase.error.ErrorHandler)7 Test (org.junit.Test)7 FakeTaskScheduler (com.karumi.rosie.testutils.FakeTaskScheduler)6 NetworkError (com.karumi.rosie.doubles.NetworkError)3 OnSuccessCallback (com.karumi.rosie.domain.usecase.callback.OnSuccessCallback)2 FakeCallbackScheduler (com.karumi.rosie.doubles.FakeCallbackScheduler)2 Success (com.karumi.rosie.domain.usecase.annotation.Success)1 ErrorNotHandledException (com.karumi.rosie.domain.usecase.error.ErrorNotHandledException)1 Character (com.karumi.rosie.sample.characters.domain.model.Character)1 CharacterDetailViewModel (com.karumi.rosie.sample.characters.view.viewmodel.CharacterDetailViewModel)1