### Question:
CreateUniqueKeyPair implements Function<RegionAndName, KeyPair> { @Override public KeyPair apply(RegionAndName from) { return createNewKeyPairInRegion(from.getRegion(), from.getName()); } @Inject  CreateUniqueKeyPair(EC2Api ec2Api, GroupNamingConvention.Factory namingConvention); @Override KeyPair apply(RegionAndName from);  }### Answer:
@Test public void testApply() throws UnknownHostException { final EC2Api client = createMock(EC2Api.class); KeyPairApi keyClient = createMock(KeyPairApi.class); KeyPair pair = createMock(KeyPair.class); expect(client.getKeyPairApi()).andReturn((Optional) Optional.of(keyClient)).atLeastOnce(); expect(keyClient.createKeyPairInRegion("region", "jclouds#group#1")).andReturn(pair); replay(client); replay(keyClient); CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() { @Override protected void configure() { Names.bindProperties(binder(), new EC2ApiMetadata().getDefaultProperties()); bind(new TypeLiteral<Supplier<String>>() { }).toInstance(Suppliers.ofInstance("1")); bind(EC2Api.class).toInstance(client); } }).getInstance(CreateUniqueKeyPair.class); assertEquals(parser.createNewKeyPairInRegion("region", "group"), pair); verify(client); verify(keyClient); }