@Test(expected = RuntimeException.class)
public void shouldCleanupKeysIfKeyCreationFails() throws IOException {

  when(serviceAccountKeyManager.serviceAccountExists(SERVICE_ACCOUNT)).thenReturn(true);
  ServiceAccountKey jsonKey = new ServiceAccountKey();
  jsonKey.setName("key.json");
  jsonKey.setPrivateKeyData("json-private-key-data");
  when(serviceAccountKeyManager.createJsonKey(any(String.class))).thenReturn(jsonKey);
  when(serviceAccountKeyManager.createP12Key(any(String.class))).thenThrow(new IOException());
  sut.ensureServiceAccountKeySecret(WORKFLOW_ID.toString(), SERVICE_ACCOUNT);
  verify(serviceAccountKeyManager).createJsonKey(SERVICE_ACCOUNT);
  verify(serviceAccountKeyManager).createP12Key(SERVICE_ACCOUNT);
  verify(serviceAccountKeyManager).tryDeleteKey(jsonKey.getName());
}