NoteListViewModel extends ViewModel<Void, NoteListModel> { public void reloadData() { loading.set(true); backgroundExecutor.execute(new Runnable() { @Override public void run() { try { final List<Note> notes = service.loadItems().getResults(); uiExecutor.execute(new Runnable() { @Override public void run() { loading.set(false); model.loadedData(notes); } }); } catch (Exception e) { uiExecutor.execute(new Runnable() { @Override public void run() { loading.set(false); model.loadedWithError(); } }); } } }); } NoteListViewModel(NoteLoader service, Executor backgroundExecutor, Executor uiExecutor, Navigator navigator); @NonNull @Override NoteListModel createModel(); @Override void resume(); void reloadData(); ObservableBoolean getLoading(); void openDetail(String objectId); void openCreateNewNote(); void onResult(int requestCode, ActivityResult activityResult); @Override int getOptionMenuId(); @Override boolean onOptionsItemSelected(int itemId);  }
@Test public void testReloadAfterError() { when(service.loadItems()) .thenThrow(new RuntimeException()) .thenReturn(TestData.response()); NoteListModel model = viewModel.initAndResume(); assertThat(model.getError().get()).isTrue(); viewModel.reloadData(); assertThat(model.getError().get()).isFalse(); assertThat(model.getItems()).hasSize(2); }