Search in sources :

Example 1 with LifecycleProvider

use of com.android.example.devsummit.archdemo.util.LifecycleProvider in project dev-summit-architecture-demo by yigit.

the class AutoCancelAsyncTaskTest method unregisterAfterCompletion.

@Test
public void unregisterAfterCompletion() {
    Executor mockExecutor = new Executor() {

        @Override
        public void execute(Runnable command) {
            command.run();
        }
    };
    LifecycleProvider provider = mock(LifecycleProvider.class);
    doNothing().when(provider).addLifecycleListener(any(LifecycleListener.class));
    AutoCancelAsyncTask<Void, Void> task = new AutoCancelAsyncTask<Void, Void>(provider) {

        @Override
        protected void onResult(Void aVoid) {
        }

        @Override
        protected Void onDoInBackground(Void... params) {
            return null;
        }
    };
    task.executeOnExecutor(mockExecutor);
    verify(provider).removeLifecycleListener(any(LifecycleListener.class));
}
Also used : Executor(java.util.concurrent.Executor) LifecycleProvider(com.android.example.devsummit.archdemo.util.LifecycleProvider) LifecycleListener(com.android.example.devsummit.archdemo.util.LifecycleListener) Test(org.junit.Test)

Example 2 with LifecycleProvider

use of com.android.example.devsummit.archdemo.util.LifecycleProvider in project dev-summit-architecture-demo by yigit.

the class AutoCancelAsyncTaskTest method unregisterOnCancel.

@Test
public void unregisterOnCancel() {
    LifecycleProvider provider = mock(LifecycleProvider.class);
    doNothing().when(provider).addLifecycleListener(any(LifecycleListener.class));
    AutoCancelAsyncTask<Void, Void> task = new AutoCancelAsyncTask<Void, Void>(provider) {

        @Override
        protected void onResult(Void aVoid) {
        }

        @Override
        protected Void onDoInBackground(Void... params) {
            return null;
        }
    };
    task.cancel(false);
    verify(provider).removeLifecycleListener(any(LifecycleListener.class));
}
Also used : LifecycleProvider(com.android.example.devsummit.archdemo.util.LifecycleProvider) LifecycleListener(com.android.example.devsummit.archdemo.util.LifecycleListener) Test(org.junit.Test)

Aggregations

LifecycleListener (com.android.example.devsummit.archdemo.util.LifecycleListener)2 LifecycleProvider (com.android.example.devsummit.archdemo.util.LifecycleProvider)2 Test (org.junit.Test)2 Executor (java.util.concurrent.Executor)1