### Question:
FileCache { public synchronized void purge() { for (File f : cacheDir.listFiles()) { String name = f.getName(); if (f.isDirectory() && NESTING_DIR_NAME_REGEX.matcher(name).matches()) { FileUtilities.deleteDir(f); } } } FileCache(File cacheDir); synchronized void purge(); FileCacheEntry addFile(File f, TaskMonitor monitor); FileCacheEntry getFile(String md5); FileCacheEntry addStream(InputStream is, TaskMonitor monitor); FileCacheEntry pushStream(DerivedFilePushProducer pusher, TaskMonitor monitor); @Override String toString(); int getFileAddCount(); int getFileReUseCount(); long getStorageEstimateBytes(); long getMaxFileAgeMS(); static final int MD5_HEXSTR_LEN; }### Answer:
@Test public void testPurge() throws IOException, CancelledException { cache = new FileCache(cacheDir); FileCacheEntry cfi = cache.addStream(toIS("This is a test1"), monitor); Assert.assertTrue(cfi.file.exists()); File f1 = new File(cacheDir, "file1"); FileUtilities.writeStringToFile(f1, "test"); File subdir = new File(cacheDir, "subdir"); subdir.mkdirs(); File f2 = new File(subdir, "file2"); FileUtilities.writeStringToFile(f2, "test2"); cache.purge(); Assert.assertFalse(cfi.file.exists()); Assert.assertTrue(f1.exists()); Assert.assertTrue(f2.exists()); }
@Test public void testPurge() throws IOException, CancelledException { FileCache cache = new FileCache(cacheDir); FileCacheEntry cfi = cache.addStream(toIS("This is a test1"), monitor); Assert.assertTrue(cfi.file.exists()); File f1 = new File(cacheDir, "file1"); FileUtilities.writeStringToFile(f1, "test"); File subdir = new File(cacheDir, "subdir"); subdir.mkdirs(); File f2 = new File(subdir, "file2"); FileUtilities.writeStringToFile(f2, "test2"); cache.purge(); Assert.assertFalse(cfi.file.exists()); Assert.assertTrue(f1.exists()); Assert.assertTrue(f2.exists()); }