use of com.octo.android.robospice.springandroid.test.model.json.WeatherResult in project robospice by stephanenicolas.
the class InFileWeatherPersisterTest method buildWeather.
private WeatherResult buildWeather(String temp, String tempUnit) {
WeatherResult weatherRequestStatus = new WeatherResult();
Weather weather = new Weather();
List<CurrenWeather> currents = new ArrayList<CurrenWeather>();
CurrenWeather current_weather = new CurrenWeather();
current_weather.setTemp(temp);
current_weather.setTemp_unit(tempUnit);
currents.add(current_weather);
weather.setCurren_weather(currents);
weatherRequestStatus.setWeather(weather);
return weatherRequestStatus;
}
use of com.octo.android.robospice.springandroid.test.model.json.WeatherResult in project robospice by stephanenicolas.
the class InFileWeatherPersisterTest method test_removeDataFromCache_when_two_requests_in_cache_and_one_removed.
public void test_removeDataFromCache_when_two_requests_in_cache_and_one_removed() throws Exception {
// GIVEN
WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP, TEST_TEMP_UNIT);
dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, FILE_NAME);
WeatherResult weatherRequestStatus2 = buildWeather(TEST_TEMP2, TEST_TEMP_UNIT);
dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus2, FILE_NAME2);
dataPersistenceManager.removeDataFromCache(FILE_NAME2);
// WHEN
List<WeatherResult> listWeatherResult = dataPersistenceManager.loadAllDataFromCache();
// THEN
assertNotNull(listWeatherResult);
assertEquals(1, listWeatherResult.size());
assertTrue(listWeatherResult.contains(weatherRequestStatus));
assertFalse(listWeatherResult.contains(weatherRequestStatus2));
}
use of com.octo.android.robospice.springandroid.test.model.json.WeatherResult in project robospice by stephanenicolas.
the class InFileWeatherPersisterTest method test_loadDataFromCache_not_expired.
public void test_loadDataFromCache_not_expired() throws Exception {
// GIVEN
WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP, TEST_TEMP_UNIT);
dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, FILE_NAME);
// WHEN
WeatherResult weatherReturned = dataPersistenceManager.loadDataFromCache(FILE_NAME, FIVE_SECONDS);
// THEN
assertEquals(TEST_TEMP, weatherReturned.getWeather().getCurren_weather().get(0).getTemp());
}
use of com.octo.android.robospice.springandroid.test.model.json.WeatherResult in project robospice by stephanenicolas.
the class InFileWeatherPersisterTest method test_saveDataAndReturnData.
public void test_saveDataAndReturnData() throws Exception {
// GIVEN
WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP, TEST_TEMP_UNIT);
// WHEN
WeatherResult weatherReturned = dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, "weather.json");
// THEN
assertEquals(TEST_TEMP, weatherReturned.getWeather().getCurren_weather().get(0).getTemp());
}
use of com.octo.android.robospice.springandroid.test.model.json.WeatherResult in project robospice by stephanenicolas.
the class InFileWeatherPersisterTest method test_loadDataFromCache_expired.
public void test_loadDataFromCache_expired() throws Exception {
// GIVEN
WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP2, TEST_TEMP_UNIT);
dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, FILE_NAME);
File cachedFile = ((Jackson2ObjectPersister<?>) dataPersistenceManager).getCacheFile(FILE_NAME);
cachedFile.setLastModified(System.currentTimeMillis() - FIVE_SECONDS);
// WHEN
WeatherResult weatherReturned = dataPersistenceManager.loadDataFromCache(FILE_NAME, DurationInMillis.ONE_SECOND);
// THEN
assertNull(weatherReturned);
}
Aggregations