CompositeDiskCache implements DiskCache { @Override public void clear() { synchronized (this) { for (int i=0; i<leafs.size(); i++) { DiskCache cache = leafs.get(i); cache.clear(); } } } CompositeDiskCache(DiskCache... caches); @Override File get(String key); @Override void put(String key, Writer writer); @Override void delete(String key); @Override void clear();  }
@Test public void testCompositeClearsToAllCaches() { DiskCache cache1 = Mockito.mock(DiskCache.class); DiskCache cache2 = Mockito.mock(DiskCache.class); DiskCache cache3 = Mockito.mock(DiskCache.class); DiskCache cache4 = Mockito.mock(DiskCache.class); CompositeDiskCache cache = new CompositeDiskCache(cache1, cache2, cache3, cache4); cache.clear(); Mockito.verify(cache1, Mockito.times(1)).clear(); Mockito.verify(cache2, Mockito.times(1)).clear(); Mockito.verify(cache3, Mockito.times(1)).clear(); Mockito.verify(cache4, Mockito.times(1)).clear(); }