String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
// create mocks
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy();
EC2TemplateOptions options = createMock(EC2TemplateOptions.class);
KeyPair keyPair = createMock(KeyPair.class);
// setup expectations
expect(options.getKeyPair()).andReturn(userSuppliedKeyPair);
expect(options.shouldAutomaticallyCreateKeyPair()).andReturn(shouldAutomaticallyCreateKeyPair);
expect(keyPair.getKeyName()).andReturn(systemGeneratedKeyPairName).atLeastOnce();
expect(strategy.credentialsMap.containsKey(new RegionAndName(region, group))).andReturn(true);
expect(strategy.credentialsMap.get(new RegionAndName(region, group))).andReturn(keyPair);
expect(options.getRunScript()).andReturn(null);
// replay mocks