Search in sources :

Example 1 with WeatherResult

use of com.octo.android.robospice.retrofit.test.model.WeatherResult in project robospice by stephanenicolas.

the class JsonObjectPersisterFactoryTest method test_loadDataFromCache_not_expired.

public void test_loadDataFromCache_not_expired() throws Exception {
    // GIVEN
    WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP, TEST_TEMP_UNIT);
    final String fileName = "toto";
    inFileObjectPersister.saveDataToCacheAndReturnData(weatherRequestStatus, fileName);
    // WHEN
    WeatherResult weatherReturned = inFileObjectPersister.loadDataFromCache(fileName, DurationInMillis.ONE_MINUTE);
    // THEN
    assertEquals(TEST_TEMP, weatherReturned.getWeather().getCurren_weather().get(0).getTemp());
}
Also used : WeatherResult(com.octo.android.robospice.retrofit.test.model.WeatherResult)

Example 2 with WeatherResult

use of com.octo.android.robospice.retrofit.test.model.WeatherResult in project robospice by stephanenicolas.

the class JsonObjectPersisterFactoryTest method test_loadDataFromCache_expired.

public void test_loadDataFromCache_expired() throws Exception {
    // GIVEN
    WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP2, TEST_TEMP_UNIT);
    final String fileName = "toto";
    inFileObjectPersister.saveDataToCacheAndReturnData(weatherRequestStatus, fileName);
    File cachedFile = ((RetrofitObjectPersister<?>) inFileObjectPersister).getCacheFile(fileName);
    final int secondsCountBackInTime = 5;
    cachedFile.setLastModified(System.currentTimeMillis() - secondsCountBackInTime * DurationInMillis.ONE_SECOND);
    // WHEN
    WeatherResult weatherReturned = inFileObjectPersister.loadDataFromCache(fileName, DurationInMillis.ONE_SECOND);
    // THEN
    assertNull(weatherReturned);
}
Also used : WeatherResult(com.octo.android.robospice.retrofit.test.model.WeatherResult) File(java.io.File)

Example 3 with WeatherResult

use of com.octo.android.robospice.retrofit.test.model.WeatherResult in project robospice by stephanenicolas.

the class JsonObjectPersisterFactoryTest method buildWeather.

private WeatherResult buildWeather(String temp, String tempUnit) {
    WeatherResult weatherRequestStatus = new WeatherResult();
    Weather weather = new Weather();
    List<Curren_weather> currents = new ArrayList<Curren_weather>();
    Curren_weather current_weather = new Curren_weather();
    current_weather.setTemp(temp);
    current_weather.setTemp_unit(tempUnit);
    currents.add(current_weather);
    weather.setCurren_weather(currents);
    weatherRequestStatus.setWeather(weather);
    return weatherRequestStatus;
}
Also used : Weather(com.octo.android.robospice.retrofit.test.model.Weather) WeatherResult(com.octo.android.robospice.retrofit.test.model.WeatherResult) ArrayList(java.util.ArrayList) Curren_weather(com.octo.android.robospice.retrofit.test.model.Curren_weather)

Example 4 with WeatherResult

use of com.octo.android.robospice.retrofit.test.model.WeatherResult in project robospice by stephanenicolas.

the class JsonObjectPersisterFactoryTest method test_loadDataFromCache_no_expiracy.

public void test_loadDataFromCache_no_expiracy() throws Exception {
    // GIVEN
    WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP, TEST_TEMP_UNIT);
    final String fileName = "toto";
    inFileObjectPersister.saveDataToCacheAndReturnData(weatherRequestStatus, fileName);
    // WHEN
    WeatherResult weatherReturned = inFileObjectPersister.loadDataFromCache(fileName, DurationInMillis.ALWAYS_RETURNED);
    // THEN
    assertEquals(TEST_TEMP, weatherReturned.getWeather().getCurren_weather().get(0).getTemp());
}
Also used : WeatherResult(com.octo.android.robospice.retrofit.test.model.WeatherResult)

Example 5 with WeatherResult

use of com.octo.android.robospice.retrofit.test.model.WeatherResult in project robospice by stephanenicolas.

the class JsonObjectPersisterFactoryTest method test_saveDataAndReturnData.

public void test_saveDataAndReturnData() throws Exception {
    // GIVEN
    WeatherResult weatherRequestStatus = buildWeather(TEST_TEMP, TEST_TEMP_UNIT);
    // WHEN
    WeatherResult weatherReturned = inFileObjectPersister.saveDataToCacheAndReturnData(weatherRequestStatus, "weather.json");
    // THEN
    assertEquals(TEST_TEMP, weatherReturned.getWeather().getCurren_weather().get(0).getTemp());
}
Also used : WeatherResult(com.octo.android.robospice.retrofit.test.model.WeatherResult)

Aggregations

WeatherResult (com.octo.android.robospice.retrofit.test.model.WeatherResult)10 RetrofitSpiceRequestStub (com.octo.android.robospice.retrofit.test.stub.RetrofitSpiceRequestStub)2 Curren_weather (com.octo.android.robospice.retrofit.test.model.Curren_weather)1 Weather (com.octo.android.robospice.retrofit.test.model.Weather)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1