OffrzLoader extends AsyncTaskLoader<JSONObject> { public JSONObject getCachedOffrz(File cachedOffrzFile){ try { final String jsonString = FileUtils.readTextFromFile(cachedOffrzFile); final JSONObject firstOffrz = new JSONObject(jsonString); if (!expired(firstOffrz)) { return firstOffrz; } throw new JSONException("Force deletion"); } catch (FileNotFoundException e) { } catch (JSONException e) { if (!cachedOffrzFile.delete()) { Timber.w("Can't delete cached offrz file"); } } catch (IOException e) { Timber.e("Can't open offrz cache"); } return null; } OffrzLoader(@NonNull Context context); JSONObject getCachedOffrz(File cachedOffrzFile); @Override JSONObject loadInBackground(); @Override void deliverResult(JSONObject data); static final long SIX_HOURS_IN_S; static final String VALIDITY_KEY; }
@Test public void checkFileNotExist(){ assertFalse(cacheFile.exists()); assertNull(loader.getCachedOffrz(cacheFile)); }