MvvmDelegate { @CallSuper public void onDestroy() { if (viewModel == null) return; if (isFinished()) { viewModel.onDestroy(); viewModel = null; } } MvvmDelegate(DelegateCallback<T, S> callback); @CallSuper void onCreate(); @CallSuper void onResume(); @CallSuper void onPause(); @CallSuper void onDestroy();  }
@Test public void testDestroyViewModelIfActivityFinished() { delegate.setFinished(true); delegate.viewModel = viewModel; delegate.onDestroy(); verify(viewModel).onDestroy(); }
@Test public void testNotDestroyViewModelIfActivityNotFinished() { delegate.setFinished(false); delegate.viewModel = viewModel; delegate.onDestroy(); verify(viewModel, never()).onDestroy(); }