@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");
  // asserting the cache is purged
  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"));
}