Predicate<RegionAndName> tester = Predicates.alwaysTrue();
SecurityGroup group = createNiceMock(SecurityGroup.class);
Set<SecurityGroup> groups = ImmutableSet.<SecurityGroup> of(group);
EC2SecurityGroupIdFromName groupIdFromName = createMock(EC2SecurityGroupIdFromName.class);
ImmutableSet.Builder<IpPermission> permissions = ImmutableSet.builder();
permissions.add(IpPermission.builder()
.fromPort(22)
.toPort(22)
.ipProtocol(IpProtocol.TCP)
.cidrBlock("0.0.0.0/0")
.build());
permissions.add(IpPermission.builder()
.fromPort(0)
.toPort(65535)
.ipProtocol(IpProtocol.TCP)
.tenantIdGroupNamePair("ownerId", "sg-123456")
.build());
permissions.add(IpPermission.builder()
.fromPort(0)
.toPort(65535)
.ipProtocol(IpProtocol.UDP)
.tenantIdGroupNamePair("ownerId", "sg-123456")
.build());
client.createSecurityGroupInRegion("region", "group", "group");
expect(group.getOwnerId()).andReturn("ownerId");
expect(groupIdFromName.apply("region/group")).andReturn("sg-123456");
client.authorizeSecurityGroupIngressInRegion("region", "sg-123456", permissions.build());
expect(client.describeSecurityGroupsInRegion("region", "group")).andReturn(Set.class.cast(groups));
replay(client);