NoteViewModel extends ViewModel<String, NoteModel> { public void reloadData() { loading.set(true); backgroundExecutor.execute(new Runnable() { @Override public void run() { executeServerCall(); } }); } NoteViewModel(Executor backgroundExecutor, Executor uiExecutor, NoteLoader noteLoader, NoteSaver noteSaver, MessageManager messageManager); @NonNull @Override NoteModel createModel(); @Override void resume(); void reloadData(); void save(); @Override ActivityResult onBackPressed(); final ObservableBoolean loading; final ObservableBoolean sending; }
@Test public void testReloadAfterError() { when(noteLoader.load(anyString())) .thenThrow(TestData.networkError()) .thenReturn(TestData.noteA()); NoteModel model = viewModel.initAndResume(TestData.ID_A); assertThat(model.getError().get()).isTrue(); viewModel.reloadData(); assertThat(model.getError().get()).isFalse(); assertThat(model.getTitle().get()).isEqualTo(TestData.TITLE_A); }