}
@Test
public void testApplyWithIllegalStateException() throws UnknownHostException {
final NovaApi api = createMock(NovaApi.class);
KeyPairApi keyApi = createMock(KeyPairApi.class);
@SuppressWarnings("unchecked")
final Supplier<String> uniqueIdSupplier = createMock(Supplier.class);
KeyPair pair = createMock(KeyPair.class);
expect(api.getKeyPairExtensionForZone("zone")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();
expect(uniqueIdSupplier.get()).andReturn("1");
expect(keyApi.create("group-1")).andThrow(new IllegalStateException());
expect(uniqueIdSupplier.get()).andReturn("2");
expect(keyApi.create("group-2")).andReturn(pair);
replay(api, keyApi, uniqueIdSupplier);
CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() {