### Question:
CachingKeyProvider extends
    KeyProviderExtension<CachingKeyProvider.CacheExtension> { @Override public KeyVersion rollNewVersion(String name, byte[] material) throws IOException { KeyVersion key = getKeyProvider().rollNewVersion(name, material); invalidateCache(name); return key; } CachingKeyProvider(KeyProvider keyProvider, long keyTimeoutMillis,
      long currKeyTimeoutMillis); @Override KeyVersion getCurrentKey(String name); @Override KeyVersion getKeyVersion(String versionName); @Override void deleteKey(String name); @Override KeyVersion rollNewVersion(String name, byte[] material); @Override KeyVersion rollNewVersion(String name); @Override void invalidateCache(String name); @Override Metadata getMetadata(String name);  }### Answer:
@Test public void testRollNewVersion() throws Exception { KeyProvider.KeyVersion mockKey = Mockito.mock(KeyProvider.KeyVersion.class); KeyProvider mockProv = Mockito.mock(KeyProvider.class); Mockito.when(mockProv.getCurrentKey(Mockito.eq("k1"))).thenReturn(mockKey); Mockito.when(mockProv.getConf()).thenReturn(new Configuration()); KeyProvider cache = new CachingKeyProvider(mockProv, 100, 100); Assert.assertEquals(mockKey, cache.getCurrentKey("k1")); Mockito.verify(mockProv, Mockito.times(1)).getCurrentKey(Mockito.eq("k1")); cache.rollNewVersion("k1"); Assert.assertEquals(mockKey, cache.getCurrentKey("k1")); Mockito.verify(mockProv, Mockito.times(2)).getCurrentKey(Mockito.eq("k1")); cache.rollNewVersion("k1", new byte[0]); Assert.assertEquals(mockKey, cache.getCurrentKey("k1")); Mockito.verify(mockProv, Mockito.times(3)).getCurrentKey(Mockito.eq("k1")); }