BaseImport { protected Boolean saveToDatabase(T data) { Boolean success = Boolean.FALSE; if (mPrefs.shouldResetData()) { mDao.deleteExistingData(); } if (data != null) { mDao.saveJsonToDatabase(data); success = Boolean.TRUE; } return success; } BaseImport(Preferences prefs, OkHttpClient client, ObjectMapper mapper, JsonToDatabaseDao<T> dao, Class<T> clazz); Observable<Boolean> importData();  }
@Test public void should_delete_existing_data_before_saving_if_specified() { when(prefs.shouldResetData()).thenReturn(true); importer.saveToDatabase(new City()); verify(dao, times(1)).deleteExistingData(); }
@Test public void should_not_delete_existing_data_before_saving_if_not_specified() { when(prefs.shouldResetData()).thenReturn(false); importer.saveToDatabase(new City()); verify(dao, times(0)).deleteExistingData(); }
@Test public void should_save_to_database_if_data_is_valid() { City data = new City(); Boolean success = importer.saveToDatabase(data); verify(dao, times(1)).saveJsonToDatabase(data); assertThat(success).isTrue(); }
@Test public void should_not_save_to_database_if_data_is_null() { City data = null; Boolean success = importer.saveToDatabase(data); verify(dao, times(0)).saveJsonToDatabase(data); assertThat(success).isFalse(); }