@Test
public void mapUuidsToKeys_whenTheActiveKeyIsTheOnlyKey_andThereAreNoCanariesInTheDatabase_andKeyCreationIsDisabled_waitsForAnotherProcessToPutACanaryToTheDatabase()
  throws Exception {

  when(encryptionKeysConfiguration.isKeyCreationEnabled()).thenReturn(false);
  when(encryptionKeysConfiguration.getProviders().get(0).getKeys()).thenReturn(asList(activeKeyData));
  when(encryptionKeysConfiguration.getProviders()).thenReturn(asList(activeProvider));
  final List<EncryptionKeyCanary> noCanaries = newArrayList();
  final List<EncryptionKeyCanary> oneCanary = Lists.newArrayList(activeKeyCanary);
  when(encryptionKeyCanaryDataService.findAll())
    .thenReturn(noCanaries)
    .thenReturn(noCanaries)
    .thenReturn(oneCanary);
  subject = new EncryptionKeyCanaryMapper(encryptionKeyCanaryDataService,
    encryptionKeysConfiguration, timedRetry, providerFactory);
  subject.mapUuidsToKeys(keySet);
  verify(encryptionKeyCanaryDataService, never()).save(any());
  verify(timedRetry).retryEverySecondUntil(eq(600L), any());
  assertThat(keySet.getActive().getUuid(), equalTo(activeCanaryUuid));
}