CreateUniqueKeyPair implements Function<RegionAndName, KeyPair> { @Override public KeyPair apply(RegionAndName from) { return createNewKeyPairInRegion(from.getRegion(), from.getName()); } @Inject  CreateUniqueKeyPair(EC2Client ec2Client, GroupNamingConvention.Factory namingConvention); @Override KeyPair apply(RegionAndName from);  }
@Test public void testApply() throws UnknownHostException { final EC2Client client = createMock(EC2Client.class); KeyPairClient keyClient = createMock(KeyPairClient.class); KeyPair pair = createMock(KeyPair.class); expect(client.getKeyPairServices()).andReturn(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(EC2Client.class).toInstance(client); } }).getInstance(CreateUniqueKeyPair.class); assertEquals(parser.createNewKeyPairInRegion("region", "group"), pair); verify(client); verify(keyClient); }