@Override
 public <DATA> InFileObjectPersister<DATA> createObjectPersister(Class<DATA> clazz) {
   InFileObjectPersister<DATA> inFileObjectPersister =
       new JacksonObjectPersister<DATA>(getApplication(), clazz, getCachePrefix());
   inFileObjectPersister.setAsyncSaveEnabled(isAsyncSaveEnabled());
   return inFileObjectPersister;
 }
  public void test_loadDataFromCache_not_expired() throws Exception {
    // GIVEN
    Weather weatherRequestStatus = buildWeather();
    final String FILE_NAME = "toto";
    dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, FILE_NAME);

    // WHEN
    Weather weatherReturned =
        dataPersistenceManager.loadDataFromCache(FILE_NAME, DurationInMillis.ONE_SECOND);

    // THEN
    assertTrue(weatherReturned.getCurren_weather().contains(TEST_TEMP));
  }
  public void test_saveDataAndReturnData_async() throws Exception {
    // GIVEN
    Weather weatherRequestStatus = buildWeather();

    // WHEN
    dataPersistenceManager.setAsyncSaveEnabled(true);
    Weather weatherReturned =
        dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, "weather.xml");

    // THEN
    ((SimpleSerializerObjectPersister<?>) dataPersistenceManager)
        .awaitForSaveAsyncTermination(500, TimeUnit.MILLISECONDS);
    assertTrue(weatherReturned.getCurren_weather().contains(TEST_TEMP));
  }
  public void test_loadDataFromCache_expired() throws Exception {
    // GIVEN
    Weather weatherRequestStatus = buildWeather();
    final String FILE_NAME = "toto";
    dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, FILE_NAME);
    File cachedFile =
        ((SimpleSerializerObjectPersister<?>) dataPersistenceManager).getCacheFile(FILE_NAME);
    cachedFile.setLastModified(System.currentTimeMillis() - 5 * DurationInMillis.ONE_SECOND);

    // WHEN
    Weather weatherReturned =
        dataPersistenceManager.loadDataFromCache(FILE_NAME, DurationInMillis.ONE_SECOND);

    // THEN
    assertNull(weatherReturned);
  }
  public void test_saveDataAndReturnData() throws Exception {
    // GIVEN
    Weather weatherRequestStatus = buildWeather();

    // WHEN
    Weather weatherReturned =
        dataPersistenceManager.saveDataToCacheAndReturnData(weatherRequestStatus, "weather.xml");

    // THEN
    assertTrue(weatherReturned.getCurren_weather().contains(TEST_TEMP));
  }
 /** for testing purpose only. Overriding allows to regive package level visibility. */
 @Override
 protected void awaitForSaveAsyncTermination(long time, TimeUnit timeUnit)
     throws InterruptedException {
   super.awaitForSaveAsyncTermination(time, timeUnit);
 }
 public void test_canHandleClientRequestStatus() {
   boolean canHandleClientWeather = dataPersistenceManager.canHandleClass(Weather.class);
   assertEquals(true, canHandleClientWeather);
 }