TasksViewModel extends BaseViewModel<TasksViewModel.State> { @Override public void onCreate() { super.onCreate(); manageSubscription(subscribe(TaskItemViewModel.Event.ON_TASK_ITEM_CLICK, new Event1<>(this::onTaskItemClick)), UnsubscribeLifeCycle.DESTROY); manageSubscription(subscribe(TaskItemViewModel.Event.ON_ACTIVE_TASK_ITEM_CLICK, new Event1<>(this::onActiveTaskItemClick)), UnsubscribeLifeCycle.DESTROY); manageSubscription(subscribe(TaskItemViewModel.Event.ON_COMPLETE_TASK_ITEM_CLICK, new Event1<>(this::onCompleteTaskItemClick)), UnsubscribeLifeCycle.DESTROY); manageSubscription(mTaskService.observeTaskCreate().compose(Transformer.applyComputationScheduler()) .subscribe(this::onTaskCreate, Throwable::printStackTrace), UnsubscribeLifeCycle.DESTROY); manageSubscription(mTaskService.observeTaskUpdate().compose(Transformer.applyComputationScheduler()) .subscribe(this::onTaskUpdate, Throwable::printStackTrace), UnsubscribeLifeCycle.DESTROY); manageSubscription(mTaskService.observeTaskRemove().compose(Transformer.applyComputationScheduler()) .subscribe(this::onTaskRemove, Throwable::printStackTrace), UnsubscribeLifeCycle.DESTROY); reloadData(false); } TasksViewModel(); @Override void onCreate(); List<Task> getTasks(); void reloadData();  }
@Test public void testOnCreate() throws Exception { doReturn(Observable.just(null)).when(mTasksViewModel.mTaskService).observeTaskCreate(); doReturn(Observable.just(null)).when(mTasksViewModel.mTaskService).observeTaskUpdate(); doReturn(Observable.just(null)).when(mTasksViewModel.mTaskService).observeTaskRemove(); doNothing().when(mTasksViewModel).onTaskCreate(null); doNothing().when(mTasksViewModel).onTaskUpdate(null); doNothing().when(mTasksViewModel).onTaskRemove(null); doNothing().when(mTasksViewModel).reloadData(anyBoolean()); mTasksViewModel.onCreate(); verify(mTasksViewModel, Mockito.times(3)).subscribe(any(Enum.class), any(Event1.class)); verify(mTasksViewModel, times(1)).subscribe(eq(TaskItemViewModel.Event.ON_TASK_ITEM_CLICK), any()); verify(mTasksViewModel, times(1)).subscribe(eq(TaskItemViewModel.Event.ON_ACTIVE_TASK_ITEM_CLICK), any()); verify(mTasksViewModel, times(1)).subscribe(eq(TaskItemViewModel.Event.ON_COMPLETE_TASK_ITEM_CLICK), any()); verify(mTasksViewModel, times(1)).onTaskCreate(null); verify(mTasksViewModel, times(1)).onTaskUpdate(null); verify(mTasksViewModel, times(1)).onTaskRemove(null); verify(mTasksViewModel, times(1)).reloadData(false); }