<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package es.voghdev.prjdagger2;

import android.content.Context;

import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

import es.voghdev.prjdagger2.global.App;
import es.voghdev.prjdagger2.global.di.MainModule;
import es.voghdev.prjdagger2.global.di.RootComponent;
import es.voghdev.prjdagger2.global.model.User;
import es.voghdev.prjdagger2.interactor.GetUsersInteractor;
import es.voghdev.prjdagger2.ui.presenter.UserListPresenter;
import es.voghdev.prjdagger2.usecase.GetUsers;

import static junit.framework.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class UserListPresenterTest {

    GetUsersInteractor mockInteractor;
    App mockApp;
    RootComponent mockComponent;
    MainModule mockModule;
    Context mockContext;
    UserListPresenter.View mockView;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(UserListPresenterTest.class);
        mockModule = mock(MainModule.class);
        mockApp = mock(App.class);
        mockContext = mock(Context.class);
        mockInteractor = mock(GetUsersInteractor.class);
        mockView = mock(UserListPresenter.View.class);
        mockComponent = mock(RootComponent.class);
    }

    @Test
    public void shouldCreateANonNullMockedPresenter() throws Exception {
        givenAMockedEnvironment();

        UserListPresenter presenter = new UserListPresenter(mockContext, mockInteractor);
        assertNotNull(presenter);
    }

    @Test
    public void shouldShowLoadingOnStart() throws Exception {
        UserListPresenter presenter = givenAMockedPresenter();

        presenter.setView(mockView);
        presenter.initialize();

        verify(mockView, times(1)).showLoading();
    }

    @Test
    public void shouldCallGetUsersOnStart() throws Exception {
        UserListPresenter presenter = givenAMockedPresenter();

        presenter.initialize();

        verify(mockInteractor, times(1)).getUsers(any(GetUsers.Listener.class));
    }

    @Test
    public void shouldSayHelloWhenAUserIsClicked() throws Exception {
        UserListPresenter presenter = givenAMockedPresenter();
        User mockUser = givenAMockedUser();

        presenter.onUserPictureClicked(mockUser);

        verify(mockView, times(1)).makeUserSayHello(mockUser);
    }

    private void givenAMockedEnvironment() {
        when(mockContext.getApplicationContext()).thenReturn(mockApp);
        when(mockApp.getComponent()).thenReturn(mockComponent);
        when(mockApp.getMainModule()).thenReturn(mockModule);
    }
<commit_msg>make code clearer<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package es.voghdev.prjdagger2;

import android.content.Context;

import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

import es.voghdev.prjdagger2.global.App;
import es.voghdev.prjdagger2.global.di.MainModule;
import es.voghdev.prjdagger2.global.di.RootComponent;
import es.voghdev.prjdagger2.global.model.User;
import es.voghdev.prjdagger2.interactor.GetUsersInteractor;
import es.voghdev.prjdagger2.ui.presenter.UserListPresenter;
import es.voghdev.prjdagger2.usecase.GetUsers;

import static junit.framework.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class UserListPresenterTest {

    GetUsersInteractor mockInteractor;
    App mockApp;
    RootComponent mockComponent;
    MainModule mockModule;
    Context mockContext;
    UserListPresenter.View mockView;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(UserListPresenterTest.class);
        mockModule = mock(MainModule.class);
        mockApp = mock(App.class);
        mockContext = mock(Context.class);
        mockInteractor = mock(GetUsersInteractor.class);
        mockView = mock(UserListPresenter.View.class);
        mockComponent = mock(RootComponent.class);
    }

    @Test
    public void shouldCreateANonNullMockedPresenter() throws Exception {
        UserListPresenter presenter = givenAMockedPresenter();
        assertNotNull(presenter);
    }

    @Test
    public void shouldShowLoadingOnStart() throws Exception {
        UserListPresenter presenter = givenAMockedPresenter();

        presenter.initialize();

        verify(mockView, times(1)).showLoading();
    }

    @Test
    public void shouldCallGetUsersOnStart() throws Exception {
        UserListPresenter presenter = givenAMockedPresenter();

        presenter.initialize();

        verify(mockInteractor, times(1)).getUsers(any(GetUsers.Listener.class));
    }

    @Test
    public void shouldSayHelloWhenAUserIsClicked() throws Exception {
        UserListPresenter presenter = givenAMockedPresenter();
        User mockUser = givenAMockedUser();

        presenter.onUserPictureClicked(mockUser);

        verify(mockView, times(1)).makeUserSayHello(mockUser);
    }

    private void givenAMockedEnvironment() {
        when(mockContext.getApplicationContext()).thenReturn(mockApp);
        when(mockApp.getComponent()).thenReturn(mockComponent);
        when(mockApp.getMainModule()).thenReturn(mockModule);
    }

{'fraction_non_alphanumeric': 0.09013398294762484, 'fraction_numerical': 0.0057856272838002435, 'mean_word_length': 3.972747918243755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4823796', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1853, 'n_words': 430}