// Path: domain/src/test/java/domain/common/BaseTest.java
// public abstract class BaseTest {
//     protected final static int WAIT = 50;
//     @Mock protected UI UIMock;
//     @Mock protected ObserveOn observeOnMock;
//     @Mock protected SubscribeOn subscribeOnMock;
// 
//     @Before public void setUp() {
//         MockitoAnnotations.initMocks(this);
//         when(observeOnMock.getScheduler()).thenReturn(Schedulers.newThread());
//         when(subscribeOnMock.getScheduler()).thenReturn(Schedulers.newThread());
//     }
// }
// 
// Path: domain/src/main/java/domain/foundation/helpers/ParserException.java
// public class ParserException extends UseCase<String> {
//     private Throwable throwable;
// 
//     @Inject public ParserException(UI ui) {
//         super(ui);
//     }
// 
//     public ParserException with(Throwable throwable) {
//         this.throwable = throwable;
//         return this;
//     }
// 
//     @Override public Observable<String> react() {
//         String message = throwable.getMessage();
// 
//         if (throwable instanceof CompositeException) {
//             message += System.getProperty("line.separator");
//             CompositeException compositeException = (CompositeException) throwable;
// 
//             for (Throwable exception : compositeException.getExceptions()) {
//                 String exceptionName = exception.getClass().getSimpleName();
//                 String exceptionMessage = exception.getMessage() != null ? exception.getMessage() : "";
//                 message += exceptionName + " -> " + exceptionMessage + System.getProperty("line.separator");
//             }
//         }
// 
//         return Observable.just(message);
//     }
// }


import org.junit.Test;
import domain.common.BaseTest;
import domain.foundation.helpers.ParserException;
import rx.Observable;
import rx.observers.TestSubscriber;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
        when(UIMock.errorNonEmptyFields()).thenReturn(oFeedback);

        TestSubscriber<String> subscriberMock = new TestSubscriber<>();
        presenterUT.safety(useCaseFailureMock.react())
                .disposable(oMock -> oMock.subscribe(subscriberMock));
        subscriberMock.awaitTerminalEvent();

        subscriberMock.assertNoErrors();
        subscriberMock.assertNoValues();

        verify(UIMock, times(0)).showFeedback(oFeedback);
    }

    @Test public void When_Subscribe_Safety_Report_Error_Observable_Failure_Nothing_Is_Emitted_And_UI_Show_Error_Is_Called() {
        TestSubscriber<String> subscriberMock = new TestSubscriber<>();
        presenterUT.safetyReportError(useCaseFailureMock.react())
                .disposable(oMock -> oMock.subscribe(subscriberMock));
        subscriberMock.awaitTerminalEvent();

        subscriberMock.assertNoErrors();
        subscriberMock.assertNoValues();

        verify(UIMock, times(1)).showFeedback(any(Observable.class));
    }

    private class PresenterUnderTest extends Presenter<BaseView> {
        final UseCaseSuccessMock useCaseSuccessMock;
        final UseCaseFailureMock useCaseFailureMock;

        public PresenterUnderTest() {
// Path: domain/src/test/java/domain/common/BaseTest.java
// public abstract class BaseTest {
//     protected final static int WAIT = 50;
//     @Mock protected UI UIMock;
//     @Mock protected ObserveOn observeOnMock;
//     @Mock protected SubscribeOn subscribeOnMock;
// 
//     @Before public void setUp() {
//         MockitoAnnotations.initMocks(this);
//         when(observeOnMock.getScheduler()).thenReturn(Schedulers.newThread());
//         when(subscribeOnMock.getScheduler()).thenReturn(Schedulers.newThread());
//     }
// }
// 
// Path: domain/src/main/java/domain/foundation/helpers/ParserException.java
// public class ParserException extends UseCase<String> {
//     private Throwable throwable;
// 
//     @Inject public ParserException(UI ui) {
//         super(ui);
//     }
// 
//     public ParserException with(Throwable throwable) {
//         this.throwable = throwable;
//         return this;
//     }
// 
//     @Override public Observable<String> react() {
//         String message = throwable.getMessage();
// 
//         if (throwable instanceof CompositeException) {
//             message += System.getProperty("line.separator");
//             CompositeException compositeException = (CompositeException) throwable;
// 
//             for (Throwable exception : compositeException.getExceptions()) {
//                 String exceptionName = exception.getClass().getSimpleName();
//                 String exceptionMessage = exception.getMessage() != null ? exception.getMessage() : "";
//                 message += exceptionName + " -> " + exceptionMessage + System.getProperty("line.separator");
//             }
//         }
// 
//         return Observable.just(message);
//     }
// }


// Path: domain/src/test/java/domain/foundation/PresenterErrorsTest.java
import org.junit.Test;
import domain.common.BaseTest;
import domain.foundation.helpers.ParserException;
import rx.Observable;
import rx.observers.TestSubscriber;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

        when(UIMock.errorNonEmptyFields()).thenReturn(oFeedback);

        TestSubscriber<String> subscriberMock = new TestSubscriber<>();
        presenterUT.safety(useCaseFailureMock.react())
                .disposable(oMock -> oMock.subscribe(subscriberMock));
        subscriberMock.awaitTerminalEvent();

        subscriberMock.assertNoErrors();
        subscriberMock.assertNoValues();

        verify(UIMock, times(0)).showFeedback(oFeedback);
    }

    @Test public void When_Subscribe_Safety_Report_Error_Observable_Failure_Nothing_Is_Emitted_And_UI_Show_Error_Is_Called() {
        TestSubscriber<String> subscriberMock = new TestSubscriber<>();
        presenterUT.safetyReportError(useCaseFailureMock.react())
                .disposable(oMock -> oMock.subscribe(subscriberMock));
        subscriberMock.awaitTerminalEvent();

        subscriberMock.assertNoErrors();
        subscriberMock.assertNoValues();

        verify(UIMock, times(1)).showFeedback(any(Observable.class));
    }

    private class PresenterUnderTest extends Presenter<BaseView> {
        final UseCaseSuccessMock useCaseSuccessMock;
        final UseCaseFailureMock useCaseFailureMock;

        public PresenterUnderTest() {
            super(null, subscribeOnMock, observeOnMock, new ParserException(UIMock), UIMock);