Program: 3989
Project: 3989
Buggy source:
/** 
 * Tests the getFiles().iterator() method.
 */
public void testSettersAndGetters() throws Exception {
  MyFileManager fileManager=(MyFileManager)injector.getInstance(FileManager.class);
  Iterator iter=null;
  Map TIME_MAP=null;
  Long old=new Long(1);
  Long middle=new Long(2);
  Long young=new Long(3);
  deleteCacheFile();
  CreationTimeCache ctCache=new CreationTimeCache(fileManager);
  assertFalse(ctCache.getFiles().iterator().hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(0,TIME_MAP.size());
  ctCache.addTime(hash1,middle.longValue());
  ctCache.commitTime(hash1);
  ctCache.persistCache();
  iter=ctCache.getFiles().iterator();
  assertEquals(hash1,iter.next());
  assertFalse(iter.hasNext());
  ctCache=null;
  ctCache=new CreationTimeCache(fileManager);
  iter=ctCache.getFiles().iterator();
  assertEquals(hash1,iter.next());
  assertFalse(iter.hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(1,TIME_MAP.size());
  ctCache.addTime(hash2,old.longValue());
  ctCache.commitTime(hash2);
  ctCache.addTime(hash3,young.longValue());
  ctCache.commitTime(hash3);
  ctCache.addTime(hash4,middle.longValue());
  ctCache.commitTime(hash4);
  ctCache.removeTime(hash1);
  ctCache.persistCache();
  iter=ctCache.getFiles().iterator();
  assertEquals(hash3,iter.next());
  iter.next();
  assertEquals(hash2,iter.next());
  assertFalse(iter.hasNext());
  ctCache=null;
  ctCache=new CreationTimeCache(fileManager);
  iter=ctCache.getFiles().iterator();
  assertEquals(hash3,iter.next());
  assertEquals(hash4,iter.next());
  assertEquals(hash2,iter.next());
  assertFalse(iter.hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(3,TIME_MAP.size());
  ctCache.removeTime(hash3);
  ctCache.persistCache();
  fileManager.setExcludeURN(hash4);
  ctCache=new CreationTimeCache(fileManager);
  iter=ctCache.getFiles().iterator();
  assertEquals(hash2,iter.next());
  assertFalse(iter.hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(1,TIME_MAP.size());
  ctCache=null;
  fileManager.clearExcludeURN();
}

Fixed version (ground truth):
/** 
 * Tests the getFiles().iterator() method.
 */
public void testSettersAndGetters() throws Exception {
  Iterator iter=null;
  Map TIME_MAP=null;
  Long old=new Long(1);
  Long middle=new Long(2);
  Long young=new Long(3);
  deleteCacheFile();
  CreationTimeCache ctCache=new CreationTimeCache(fileManager);
  assertFalse(ctCache.getFiles().iterator().hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(0,TIME_MAP.size());
  ctCache.addTime(hash1,middle.longValue());
  ctCache.commitTime(hash1);
  ctCache.persistCache();
  iter=ctCache.getFiles().iterator();
  assertEquals(hash1,iter.next());
  assertFalse(iter.hasNext());
  ctCache=null;
  ctCache=new CreationTimeCache(fileManager);
  iter=ctCache.getFiles().iterator();
  assertEquals(hash1,iter.next());
  assertFalse(iter.hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(1,TIME_MAP.size());
  ctCache.addTime(hash2,old.longValue());
  ctCache.commitTime(hash2);
  ctCache.addTime(hash3,young.longValue());
  ctCache.commitTime(hash3);
  ctCache.addTime(hash4,middle.longValue());
  ctCache.commitTime(hash4);
  ctCache.removeTime(hash1);
  ctCache.persistCache();
  iter=ctCache.getFiles().iterator();
  assertEquals(hash3,iter.next());
  iter.next();
  assertEquals(hash2,iter.next());
  assertFalse(iter.hasNext());
  ctCache=null;
  ctCache=new CreationTimeCache(fileManager);
  iter=ctCache.getFiles().iterator();
  assertEquals(hash3,iter.next());
  assertEquals(hash4,iter.next());
  assertEquals(hash2,iter.next());
  assertFalse(iter.hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(3,TIME_MAP.size());
  ctCache.removeTime(hash3);
  ctCache.persistCache();
  fileManager.getGnutellaSharedFileList().remove(fd4);
  ctCache=new CreationTimeCache(fileManager);
  iter=ctCache.getFiles().iterator();
  assertEquals(hash2,iter.next());
  assertFalse(iter.hasNext());
  TIME_MAP=getUrnToTime(ctCache);
  assertEquals(1,TIME_MAP.size());
}