### Question:
ImportOrReturnExistingKeypair implements Function<RegionNameAndPublicKeyMaterial, KeyPair> { @Override public KeyPair apply(RegionNameAndPublicKeyMaterial from) { return importOrReturnExistingKeypair(from.getRegion(), from.getName(), from.getPublicKeyMaterial()); } @Inject  ImportOrReturnExistingKeypair(AWSEC2Api ec2Api); @Override KeyPair apply(RegionNameAndPublicKeyMaterial from); KeyPair addFingerprintToKeyPair(String publicKeyMaterial, KeyPair keyPair);  }### Answer:
@Test public void testApply() { AWSEC2Api client = createMock(AWSEC2Api.class); AWSKeyPairApi keyApi = createMock(AWSKeyPairApi.class); expect(client.getKeyPairApi()).andReturn((Optional) Optional.of(keyApi)).atLeastOnce(); expect(keyApi.importKeyPairInRegion("region", "jclouds#group", PUBLIC_KEY)).andReturn(pair); replay(client); replay(keyApi); ImportOrReturnExistingKeypair parser = new ImportOrReturnExistingKeypair(client); assertEquals(parser.importOrReturnExistingKeypair("region", "group", PUBLIC_KEY), pairWithFingerprint); verify(client); verify(keyApi); }