<commit_before>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();
    }
}<commit_msg>Update CacheDetailPresenter unit tests<commit_after>package io.github.plastix.forage.ui.cachedetail;

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

import io.github.plastix.forage.data.api.auth.OAuthInteractor;
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 OAuthInteractor oAuthInteractor;
    private CacheDetailView view;

    @Before
    public void beforeEachTest() {
        view = mock(CacheDetailView.class);
        databaseInteractor = mock(DatabaseInteractor.class);
        oAuthInteractor = mock(OAuthInteractor.class);
        cacheDetailPresenter = new CacheDetailPresenter(databaseInteractor, oAuthInteractor);
        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();
    }

    @Test
    public void openLogScreen_shouldOpenActivity() {
        when(oAuthInteractor.hasSavedOAuthTokens()).thenReturn(true);

        cacheDetailPresenter.openLogScreen();

        verify(view, only()).openLogScreen();
    }

    @Test
    public void openLogScreen_shouldShowError() {
        when(oAuthInteractor.hasSavedOAuthTokens()).thenReturn(false);

        cacheDetailPresenter.openLogScreen();

        verify(view, only()).onErrorRequiresLogin();
    }
}
{'fraction_non_alphanumeric': 0.0994268077601411, 'fraction_numerical': 0.0, 'mean_word_length': 4.035516093229745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3961539', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1286, 'n_words': 203}