Search in sources :

Example 6 with OnErrorCallback

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

Example 7 with OnErrorCallback

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

the class UseCaseWrapperTest method shouldNotifyErrorNotifiedFromTheUseCase.

@Test
public void shouldNotifyErrorNotifiedFromTheUseCase() {
    AnyUseCase anyUseCase = new AnyUseCase();
    anyUseCase.setErrorToNotify(new Error());
    UseCaseParams argsParams = givenUseCaseParamsWithArgs(ANY_FIRST_ARG, ANY_SECOND_ARG);
    ErrorHandler errorHandler = mock(ErrorHandler.class);
    UseCaseWrapper useCaseWrapper = new UseCaseWrapper(anyUseCase, argsParams, errorHandler);
    useCaseWrapper.execute();
    verify(errorHandler).notifyException(any(ErrorNotHandledException.class), eq((OnErrorCallback) null));
}
Also used : OnErrorCallback(com.karumi.rosie.domain.usecase.error.OnErrorCallback) ErrorHandler(com.karumi.rosie.domain.usecase.error.ErrorHandler) ErrorNotHandledException(com.karumi.rosie.domain.usecase.error.ErrorNotHandledException) Test(org.junit.Test)

Example 8 with OnErrorCallback

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

the class UseCaseHandler method execute.

/**
   * Given a class configured with UseCase annotation executes the annotated
   * method out of the UI thread and returns the response, if needed, on the UI thread.
   *
   * @param useCase the use case to invoke.
   * @param useCaseParams params to use on the invocation.
   */
void execute(RosieUseCase useCase, UseCaseParams useCaseParams) {
    UseCaseFilter.filter(useCase, useCaseParams);
    useCase.setOnSuccessCallback(useCaseParams.getOnSuccessCallback());
    OnErrorCallback onErrorCallback = new OnErrorCallbackToErrorHandlerAdapter(errorHandler, useCaseParams.getOnErrorCallback());
    errorCallbacks.add(onErrorCallback);
    useCase.setOnErrorCallback(onErrorCallback);
    UseCaseWrapper useCaseWrapper = new UseCaseWrapper(useCase, useCaseParams, errorHandler);
    taskScheduler.execute(useCaseWrapper);
}
Also used : OnErrorCallback(com.karumi.rosie.domain.usecase.error.OnErrorCallback)

Example 9 with OnErrorCallback

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

the class CharacterDetailsPresenter method loadCharacterDetails.

private void loadCharacterDetails() {
    getView().hideCharacterDetail();
    createUseCaseCall(getCharacterDetails).args(characterKey).onSuccess(new OnSuccessCallback() {

        @Success
        public void onCharacterDetailsLoaded(Character character) {
            hideLoading();
            CharacterDetailViewModel characterDetailViewModel = mapper.mapCharacterToCharacterDetailViewModel(character);
            getView().showCharacterDetail(characterDetailViewModel);
        }
    }).onError(new OnErrorCallback() {

        @Override
        public boolean onError(Error error) {
            getView().hideLoading();
            return false;
        }
    }).execute();
}
Also used : OnErrorCallback(com.karumi.rosie.domain.usecase.error.OnErrorCallback) Character(com.karumi.rosie.sample.characters.domain.model.Character) CharacterDetailViewModel(com.karumi.rosie.sample.characters.view.viewmodel.CharacterDetailViewModel) OnSuccessCallback(com.karumi.rosie.domain.usecase.callback.OnSuccessCallback) Success(com.karumi.rosie.domain.usecase.annotation.Success)

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