@Test
  public void testRemoveWithIterator() throws Exception {
    DefaultDiskStorage storage = getStorageSupplier(1).get();

    final String resourceId1 = "resource1";
    final byte[] value1 = new byte[100];
    value1[80] = 101;
    final String resourceId2 = "resource2";
    final byte[] value2 = new byte[104];
    value2[80] = 102;
    final String resourceId3 = "resource3";
    final byte[] value3 = new byte[106];
    value3[80] = 103;

    writeFileToStorage(storage, resourceId1, value1);

    final long time2 = 1000L;
    when(mClock.now()).thenReturn(time2);
    writeFileToStorage(storage, resourceId2, value2);

    when(mClock.now()).thenReturn(2000L);
    writeFileToStorage(storage, resourceId3, value3);

    List<File> files = findNewFiles(mDirectory, Collections.<File>emptySet(), /*recurse*/ true);

    // there should be 1 file per entry
    assertEquals(3, files.size());

    // now delete entry2
    Collection<DiskStorage.Entry> entries = storage.getEntries();
    for (DiskStorage.Entry entry : entries) {
      if (Math.abs(entry.getTimestamp() - time2) < 500) {
        storage.remove(entry);
      }
    }

    assertFalse(storage.contains(resourceId2, null));
    List<File> remaining = findNewFiles(mDirectory, Collections.<File>emptySet(), /*recurse*/ true);

    // 2 entries remain
    assertEquals(2, remaining.size());

    // none of them with timestamp close to time2
    List<DiskStorage.Entry> entries1 = new ArrayList<>(storage.getEntries());
    assertEquals(2, entries1.size());
    // first
    DiskStorage.Entry entry = entries1.get(0);
    assertFalse(Math.abs(entry.getTimestamp() - time2) < 500);
    // second
    entry = entries1.get(1);
    assertFalse(Math.abs(entry.getTimestamp() - time2) < 500);
  }
Inserts 3 files with different dates. Check what files are there. Uses an iterator to remove
the one in the middle. Check that later.

@throws Exception
imagepipeline-base/src/test/java/com/facebook/cache/disk/DefaultDiskStorageTest.java