@Test
public void testCacheNeedsCleaning1Left() throws Exception {
File testCacheFolder = TestFileUtil.createTempDirectoryInSystemTemp();
Cache cache = new Cache(testCacheFolder);
cache.setKeepBytes(50*1024);
TestFileUtil.createRandomFile(new File(testCacheFolder, "10"), 10*1024);
Thread.sleep(1001); // Linux/ext3 only has 1s accuracy
TestFileUtil.createRandomFile(new File(testCacheFolder, "30"), 30*1024);
Thread.sleep(1001);
TestFileUtil.createRandomFile(new File(testCacheFolder, "20"), 20*1024);
Thread.sleep(1001);
TestFileUtil.createRandomFile(new File(testCacheFolder, "40"), 40*1024);
assertEquals(4, testCacheFolder.listFiles().length);
cache.clear();
assertEquals(1, testCacheFolder.listFiles().length);
assertFalse(new File(testCacheFolder, "10").exists());
assertFalse(new File(testCacheFolder, "30").exists());
assertFalse(new File(testCacheFolder, "20").exists());