Search in sources :

Example 11 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseActivityTest method testShouldCallOnOptionsItemSelected.

@Test
public void testShouldCallOnOptionsItemSelected() {
    BaseActivity baseActivity = new TestBaseActivity();
    baseActivity.onCreate(null);
    BasePresenter presenter = baseActivity.getPresenter();
    when(presenter.onOptionsItemSelected(any(MenuItem.class))).thenReturn(false);
    MenuItem menuItem = Mockito.mock(MenuItem.class);
    verify(presenter, times(0)).onOptionsItemSelected(menuItem);
    assertFalse(baseActivity.onOptionsItemSelected(menuItem));
    verify(presenter, times(1)).onOptionsItemSelected(menuItem);
    when(presenter.onOptionsItemSelected(any(MenuItem.class))).thenReturn(true);
    assertTrue(baseActivity.onOptionsItemSelected(menuItem));
    verify(presenter, times(2)).onOptionsItemSelected(menuItem);
}
Also used : MenuItem(android.view.MenuItem) BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 12 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseActivityTest method testShouldCallOnBackPressed.

@Test
public void testShouldCallOnBackPressed() {
    BaseActivity baseActivity = new TestBaseActivity();
    baseActivity.onCreate(null);
    BasePresenter presenter = baseActivity.getPresenter();
    when(presenter.onBackPressed()).thenReturn(false);
    verify(presenter, times(0)).onBackPressed();
    baseActivity.onBackPressed();
    verify(presenter, times(1)).onBackPressed();
    when(presenter.onBackPressed()).thenReturn(true);
    baseActivity.onBackPressed();
    verify(presenter, times(2)).onBackPressed();
}
Also used : BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 13 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseAppCompatActivityTest method testShouldCallOnBackPressed.

@Test
public void testShouldCallOnBackPressed() {
    BaseAppCompatActivity baseActivity = new TestBaseAppCompatActivity();
    baseActivity.onCreate(null);
    BasePresenter presenter = baseActivity.getPresenter();
    when(presenter.onBackPressed()).thenReturn(false);
    verify(presenter, times(0)).onBackPressed();
    baseActivity.onBackPressed();
    verify(presenter, times(1)).onBackPressed();
    when(presenter.onBackPressed()).thenReturn(true);
    baseActivity.onBackPressed();
    verify(presenter, times(2)).onBackPressed();
}
Also used : BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 14 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseAppCompatActivityTest method testShouldCallOnCreateOptionsMenu.

@Test
public void testShouldCallOnCreateOptionsMenu() {
    final MenuInflater menuInflater = Mockito.mock(MenuInflater.class);
    BaseAppCompatActivity baseActivity = new TestBaseAppCompatActivity() {

        @NonNull
        @Override
        public MenuInflater getMenuInflater() {
            return menuInflater;
        }
    };
    baseActivity.onCreate(null);
    BasePresenter presenter = baseActivity.getPresenter();
    Menu menu = Mockito.mock(Menu.class);
    verify(presenter, times(0)).onCreateOptionsMenu(menu, menuInflater);
    baseActivity.onCreateOptionsMenu(menu);
    verify(presenter, times(1)).onCreateOptionsMenu(menu, menuInflater);
}
Also used : MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 15 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseActivity method onBackPressed.

@Override
public void onBackPressed() {
    BasePresenter presenter = getPresenter();
    if (presenter != null && presenter.onBackPressed()) {
        return;
    }
    super.onBackPressed();
}
Also used : BasePresenter(com.skocken.presentation.presenter.BasePresenter)

Aggregations

BasePresenter (com.skocken.presentation.presenter.BasePresenter)16 Test (org.junit.Test)10 Intent (android.content.Intent)2 Menu (android.view.Menu)2 MenuInflater (android.view.MenuInflater)2 MenuItem (android.view.MenuItem)2 WeakReference (java.lang.ref.WeakReference)2