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);
}
}
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);
}
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());
}
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);
}
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);
}
Aggregations