@Test
  public void testIterationAndRemoval() throws Exception {
    DefaultDiskStorage storage = getStorageSupplier(1).get();
    final String resourceId0 = "file0";
    final String resourceId1 = "file1";
    final String resourceId2 = "file2";
    final String resourceId3 = "file3";

    final byte[] CONTENT0 = "content0".getBytes("UTF-8");
    final byte[] CONTENT1 = "content1-bigger".getBytes("UTF-8");
    final byte[] CONTENT2 = "content2".getBytes("UTF-8");
    final byte[] CONTENT3 = "content3-biggest".getBytes("UTF-8");

    List<File> files = new ArrayList<>(4);
    files.add(write(storage, resourceId0, CONTENT0));
    when(mClock.now()).thenReturn(1000L);
    files.add(write(storage, resourceId1, CONTENT1));
    when(mClock.now()).thenReturn(2000L);
    files.add(write(storage, resourceId2, CONTENT2));
    when(mClock.now()).thenReturn(3000L);
    files.add(write(storage, resourceId3, CONTENT3));

    List<DefaultDiskStorage.EntryImpl> entries = retrieveEntries(storage);
    Assert.assertEquals(4, entries.size());
    Assert.assertEquals(files.get(0), entries.get(0).getResource().getFile());
    Assert.assertEquals(files.get(1), entries.get(1).getResource().getFile());
    Assert.assertEquals(files.get(2), entries.get(2).getResource().getFile());
    Assert.assertEquals(files.get(3), entries.get(3).getResource().getFile());

    // try the same after removing 2 entries
    for (DiskStorage.Entry entry : storage.getEntries()) {
      // delete the 2 biggest files: key1 and key3 (see the content values)
      if (entry.getSize() >= CONTENT1.length) {
        storage.remove(entry);
      }
    }

    List<DefaultDiskStorage.EntryImpl> entriesAfterRemoval = retrieveEntries(storage);
    Assert.assertEquals(2, entriesAfterRemoval.size());
    Assert.assertEquals(files.get(0), entriesAfterRemoval.get(0).getResource().getFile());
    Assert.assertEquals(files.get(2), entriesAfterRemoval.get(1).getResource().getFile());
  }
Test the iterator returned is ok and deletion through the iterator is ok too. This is the
required functionality that eviction needs.

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