package io.github.plastix.forage.ui.cachedetail;

import org.junit.Before;
import org.junit.Test;

import io.github.plastix.forage.data.local.DatabaseInteractor;
import io.github.plastix.forage.data.local.model.Cache;
import rx.Single;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class CacheDetailPresenterTest {

    private CacheDetailPresenter cacheDetailPresenter;
    private DatabaseInteractor databaseInteractor;
    private CacheDetailView view;

    @Before
    public void beforeEachTest() {
        view = mock(CacheDetailView.class);
        databaseInteractor = mock(DatabaseInteractor.class);
        cacheDetailPresenter = new CacheDetailPresenter(databaseInteractor);
        cacheDetailPresenter.onViewAttached(view);
    }

    @Test
    public void onDestroy_shouldCallDatabaseInteractorDestroy() {
        cacheDetailPresenter.onDestroyed();
        verify(databaseInteractor, only()).onDestroy();
    }

    @Test
    public void getGeocache_shouldCallViewReturnedGeocache() {
        Cache cache = mock(Cache.class);
        String cacheCode = "geocache code";
        when(databaseInteractor.getGeocacheCopy(cacheCode)).thenReturn(Single.just(cache));

        cacheDetailPresenter.getGeocache(cacheCode);

        verify(databaseInteractor, only()).getGeocacheCopy(cacheCode);
        verify(view, only()).returnedGeocache(cache);
    }

    @Test
    public void getGeocache_shouldCallViewError() {
        String cacheCode = "geocache code";
        when(databaseInteractor.getGeocacheCopy(cacheCode))
                .thenReturn(Single.<Cache>error(new Throwable("Error")));

        cacheDetailPresenter.getGeocache(cacheCode);

        verify(databaseInteractor, only()).getGeocacheCopy(cacheCode);
        verify(view, only()).onError();
    }
}

@@ -92,16 +92,79 @@
 .Test;%0A%0A
+import io.github.plastix.forage.data.api.auth.OAuthInteractor;%0A
 import i
@@ -210,32 +210,32 @@
 baseInteractor;%0A
-
 import io.github
@@ -603,16 +603,61 @@
 ractor;%0A
+    private OAuthInteractor oAuthInteractor;%0A
     priv
@@ -827,32 +827,87 @@
 eractor.class);%0A
+        oAuthInteractor = mock(OAuthInteractor.class);%0A
         cacheDet
@@ -964,16 +964,33 @@
 teractor
+, oAuthInteractor
 );%0A     
@@ -2020,32 +2020,32 @@
 opy(cacheCode);%0A
-
         verify(v
@@ -2073,11 +2073,484 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void openLogScreen_shouldOpenActivity() %7B%0A        when(oAuthInteractor.hasSavedOAuthTokens()).thenReturn(true);%0A%0A        cacheDetailPresenter.openLogScreen();%0A%0A        verify(view, only()).openLogScreen();%0A    %7D%0A%0A    @Test%0A    public void openLogScreen_shouldShowError() %7B%0A        when(oAuthInteractor.hasSavedOAuthTokens()).thenReturn(false);%0A%0A        cacheDetailPresenter.openLogScreen();%0A%0A        verify(view, only()).onErrorRequiresLogin();%0A    %7D
 %0A%7D%0A

Update CacheDetailPresenter unit tests