ImportOrReturnExistingKeypair implements Function<RegionNameAndPublicKeyMaterial, KeyPair> { @Override public KeyPair apply(RegionNameAndPublicKeyMaterial from) { return importOrReturnExistingKeypair(from.getRegion(), from.getName(), from.getPublicKeyMaterial()); } @Inject  ImportOrReturnExistingKeypair(AWSEC2Client ec2Client); @Override KeyPair apply(RegionNameAndPublicKeyMaterial from); KeyPair addFingerprintToKeyPair(String publicKeyMaterial, KeyPair keyPair);  }
@Test public void testApply() { AWSEC2Client client = createMock(AWSEC2Client.class); AWSKeyPairClient keyClient = createMock(AWSKeyPairClient.class); expect(client.getKeyPairServices()).andReturn(keyClient).atLeastOnce(); expect(keyClient.importKeyPairInRegion("region", "jclouds#group", PUBLIC_KEY)).andReturn(pair); replay(client); replay(keyClient); ImportOrReturnExistingKeypair parser = new ImportOrReturnExistingKeypair(client); assertEquals(parser.importOrReturnExistingKeypair("region", "group", PUBLIC_KEY), pairWithFingerprint); verify(client); verify(keyClient); }