### Question:
ResourceCache { public File cacheFile (File fileToCache, String cacheSubdir, String digest) throws IOException { File cacheLocation = new File(_cacheDir, cacheSubdir); createDirectoryIfNecessary(cacheLocation); File cachedFile = new File(cacheLocation, digest + getFileSuffix(fileToCache)); File lastAccessedFile = new File( cacheLocation, cachedFile.getName() + LAST_ACCESSED_FILE_SUFFIX); if (!cachedFile.exists()) { createNewFile(cachedFile); FileUtil.copy(fileToCache, cachedFile); } if (lastAccessedFile.exists()) { lastAccessedFile.setLastModified(System.currentTimeMillis()); } else { createNewFile(lastAccessedFile); } return cachedFile; } ResourceCache(File _cacheDir); File cacheFile(File fileToCache, String cacheSubdir, String digest);  }### Answer:
@Test public void shouldCacheFile () throws IOException { assertEquals("abc123" + extension, cacheFile().getName()); }
@Test public void shouldTrackFileUsage () throws IOException { String name = "abc123" + extension + ResourceCache.LAST_ACCESSED_FILE_SUFFIX; File lastAccessedFile = new File(cacheFile().getParentFile(), name); assertTrue(lastAccessedFile.exists()); }
@Test public void shouldNotCacheTheSameFile () throws Exception { File cachedFile = cacheFile(); cachedFile.setLastModified(YESTERDAY); long expectedLastModified = cachedFile.lastModified(); File sameCachedFile = cacheFile(); assertEquals(expectedLastModified, sameCachedFile.lastModified()); }
@Test public void shouldRememberWhenFileWasRequested () throws Exception { File cachedFile = cacheFile(); String name = cachedFile.getName() + ResourceCache.LAST_ACCESSED_FILE_SUFFIX; File lastAccessedFile = new File(cachedFile.getParentFile(), name); lastAccessedFile.setLastModified(YESTERDAY); long lastAccessed = lastAccessedFile.lastModified(); cacheFile(); assertTrue(lastAccessedFile.lastModified() > lastAccessed); }