use of com.skocken.presentation.util.ActivityLifecycleCallbackDelegate in project Presentation by StanKocken.
the class ActivityLifecycleCallbackDelegateTest method testShouldRelease.
@Test
public void testShouldRelease() {
ActivityLifecycleCallbackDelegate.track(mActivity, mListener);
ArgumentCaptor<Application.ActivityLifecycleCallbacks> argumentCaptor = ArgumentCaptor.forClass(Application.ActivityLifecycleCallbacks.class);
verify(mApplication).registerActivityLifecycleCallbacks(argumentCaptor.capture());
ActivityLifecycleCallbackDelegate activityLifecycleCallbackDelegate = (ActivityLifecycleCallbackDelegate) argumentCaptor.getValue();
verify(mApplication, times(0)).unregisterActivityLifecycleCallbacks(activityLifecycleCallbackDelegate);
verify(mListener, times(0)).onResume();
activityLifecycleCallbackDelegate.onActivityResumed(mActivity);
verify(mListener, times(1)).onResume();
activityLifecycleCallbackDelegate.release();
verify(mApplication, times(1)).unregisterActivityLifecycleCallbacks(activityLifecycleCallbackDelegate);
// test no more listener callback
verify(mListener, times(1)).onResume();
activityLifecycleCallbackDelegate.onActivityResumed(mActivity);
verify(mListener, times(1)).onResume();
}
use of com.skocken.presentation.util.ActivityLifecycleCallbackDelegate in project Presentation by StanKocken.
the class ActivityLifecycleCallbackDelegateTest method testShouldCallListener.
@Test
public void testShouldCallListener() {
Activity otherActivity = Mockito.mock(Activity.class);
ActivityLifecycleCallbackDelegate.track(mActivity, mListener);
ArgumentCaptor<Application.ActivityLifecycleCallbacks> argumentCaptor = ArgumentCaptor.forClass(Application.ActivityLifecycleCallbacks.class);
verify(mApplication).registerActivityLifecycleCallbacks(argumentCaptor.capture());
ActivityLifecycleCallbackDelegate activityLifecycleCallbackDelegate = (ActivityLifecycleCallbackDelegate) argumentCaptor.getValue();
verify(mListener, times(0)).onCreate(null);
activityLifecycleCallbackDelegate.onActivityCreated(otherActivity, null);
verify(mListener, times(0)).onCreate(null);
activityLifecycleCallbackDelegate.onActivityCreated(mActivity, null);
verify(mListener, times(1)).onCreate(null);
verify(mListener, times(0)).onStart();
activityLifecycleCallbackDelegate.onActivityStarted(otherActivity);
verify(mListener, times(0)).onStart();
activityLifecycleCallbackDelegate.onActivityStarted(mActivity);
verify(mListener, times(1)).onStart();
verify(mListener, times(0)).onResume();
activityLifecycleCallbackDelegate.onActivityResumed(otherActivity);
verify(mListener, times(0)).onResume();
activityLifecycleCallbackDelegate.onActivityResumed(mActivity);
verify(mListener, times(1)).onResume();
verify(mListener, times(0)).onPause();
activityLifecycleCallbackDelegate.onActivityPaused(otherActivity);
verify(mListener, times(0)).onPause();
activityLifecycleCallbackDelegate.onActivityPaused(mActivity);
verify(mListener, times(1)).onPause();
verify(mListener, times(0)).onStop();
activityLifecycleCallbackDelegate.onActivityStopped(otherActivity);
verify(mListener, times(0)).onStop();
activityLifecycleCallbackDelegate.onActivityStopped(mActivity);
verify(mListener, times(1)).onStop();
verify(mListener, times(0)).onSaveInstanceState(null);
activityLifecycleCallbackDelegate.onActivitySaveInstanceState(otherActivity, null);
verify(mListener, times(0)).onSaveInstanceState(null);
activityLifecycleCallbackDelegate.onActivitySaveInstanceState(mActivity, null);
verify(mListener, times(1)).onSaveInstanceState(null);
verify(mListener, times(0)).onDestroy();
activityLifecycleCallbackDelegate.onActivityDestroyed(otherActivity);
verify(mListener, times(0)).onDestroy();
activityLifecycleCallbackDelegate.onActivityDestroyed(mActivity);
verify(mListener, times(1)).onDestroy();
}
use of com.skocken.presentation.util.ActivityLifecycleCallbackDelegate in project Presentation by StanKocken.
the class BasePresenter method onDestroy.
@Override
public void onDestroy() {
if (mActivityLifecycleCallbackDelegate != null) {
ActivityLifecycleCallbackDelegate activityLifecycleCallbackDelegate = mActivityLifecycleCallbackDelegate.get();
if (activityLifecycleCallbackDelegate != null) {
activityLifecycleCallbackDelegate.release();
}
mActivityLifecycleCallbackDelegate = null;
}
}
Aggregations