@Test
public void mapUuidsToKeys_whenTheActiveKeyIsTheOnlyKey_whenThereIsAMatchingCanaryInTheDatabase_shouldMapTheKeyToTheMatchingCanary()
  throws Exception {

  when(encryptionKeysConfiguration.isKeyCreationEnabled()).thenReturn(true);
  when(encryptionKeysConfiguration.getProviders().get(0).getKeys()).thenReturn(asList(activeKeyData));
  when(encryptionKeysConfiguration.getProviders()).thenReturn(asList(activeProvider));
  when(encryptionKeyCanaryDataService.findAll()).thenReturn(asArrayList(activeKeyCanary));
  when(encryptionService
    .decrypt(activeKey, activeKeyCanary.getEncryptedCanaryValue(),
      activeKeyCanary.getNonce()))
    .thenReturn(CANARY_VALUE);
  subject = new EncryptionKeyCanaryMapper(encryptionKeyCanaryDataService,
    encryptionKeysConfiguration, timedRetry, providerFactory);
  subject.mapUuidsToKeys(keySet);
  assertThat(keySet.get(activeCanaryUuid).getKey(), equalTo(activeKey));
  verify(encryptionService, times(0))
    .encrypt(eq(activeCanaryUuid), eq(activeKey), any(String.class));
  assertThat(keySet.getActive().getUuid(), equalTo(activeCanaryUuid));
}