Search in sources :

Example 1 with BasePresenter

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

the class BaseAppCompatActivity method initPresenter.

void initPresenter(Bundle savedInstanceState) {
    BasePresenter presenter = newPresenter();
    setPresenter(presenter);
    if (presenter != null) {
        // because the first onCreate won't be call otherwise (creation too late)
        presenter.onCreate(savedInstanceState);
    }
}
Also used : BasePresenter(com.skocken.presentation.presenter.BasePresenter)

Example 2 with BasePresenter

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

the class BaseActivityTest method testShouldCallOnCreateOptionsMenu.

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

        @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 3 with BasePresenter

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

the class BaseAppCompatActivityTest method testShouldWeakReferenceOnPresenter.

@Test
public void testShouldWeakReferenceOnPresenter() {
    BasePresenter basePresenter = new BasePresenter(null, null) {
    };
    final WeakReference<BasePresenter> weakReferencePresenter = new WeakReference<>(basePresenter);
    BaseAppCompatActivity baseActivity = new TestBaseAppCompatActivity() {

        @Override
        protected BasePresenter newPresenter() {
            return weakReferencePresenter.get();
        }
    };
    baseActivity.onCreate(null);
    assertEquals(basePresenter, baseActivity.getPresenter());
    basePresenter = null;
    for (int i = 0; i < 10 && weakReferencePresenter.get() != null; i++) {
        System.gc();
    }
    assertNull(basePresenter);
    assertNull(weakReferencePresenter.get());
    assertNull(baseActivity.getPresenter());
}
Also used : WeakReference(java.lang.ref.WeakReference) BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 4 with BasePresenter

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

the class BaseAppCompatActivityTest method testShouldCallOnActivityResult.

@Test
public void testShouldCallOnActivityResult() {
    BaseAppCompatActivity baseActivity = new TestBaseAppCompatActivity();
    baseActivity.onCreate(null);
    BasePresenter presenter = baseActivity.getPresenter();
    int requestCode = 432;
    int resultCode = 542;
    Intent intent = Mockito.mock(Intent.class);
    verify(presenter, times(0)).onActivityResult(requestCode, resultCode, intent);
    baseActivity.onActivityResult(requestCode, resultCode, intent);
    verify(presenter, times(1)).onActivityResult(requestCode, resultCode, intent);
}
Also used : Intent(android.content.Intent) BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 5 with BasePresenter

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

the class BaseAppCompatActivityTest method testShouldCallOnOptionsItemSelected.

@Test
public void testShouldCallOnOptionsItemSelected() {
    BaseAppCompatActivity baseActivity = new TestBaseAppCompatActivity();
    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)

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