### Question:
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { void processInvalidGroups (Collection<String> securityGroupIds) { log.info("Removing {} from cached Security Groups for Chaos", v("Security Group IDs", securityGroupIds)); vpcToSecurityGroupMap.values().removeAll(securityGroupIds); } @Autowired  AwsEC2Platform(AmazonEC2 amazonEC2, ContainerManager containerManager, AwsEC2SelfAwareness awsEC2SelfAwareness); private  AwsEC2Platform(); void setFilter(@NotNull Map<String, List<String>> filter); void setGroupingTags(List<String> groupingTags); void setSSHPrivateKeys(@NotNull Map<String, String> sshPrivateKeys); Map<String, String> getImageIdToUsernameMap(); void setImageIdToUsernameMap(Map<String, String> imageIdToUsernameMap); @Override ApiStatus getApiStatus(); @JsonIgnore Collection<SubnetUtils.SubnetInfo> getRoutableCidrBlocks(); void setRoutableCidrBlocks(Collection<String> routableCidrBlocks); boolean isAddressRoutable(String privateIPAddress); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override List<Container> generateRoster(); @Override boolean isContainerRecycled(Container container); ContainerHealth checkHealth(String instanceId); void stopInstance(String... instanceIds); void terminateInstance(String... instanceIds); void startInstance(String... instanceIds); void restartInstance(String... instanceIds); void setSecurityGroupIds(String networkInterfaceId, Collection<String> securityGroupIds); String getChaosSecurityGroupForInstance(String instanceId); boolean isContainerTerminated(String instanceId); boolean isAutoscalingGroupAtDesiredInstances(String autoScalingGroupName); boolean hasKey(String keyName); @Override void recycleContainer(AwsEC2Container container); void triggerAutoscalingUnhealthy(String instanceId); @Override String getEndpoint(AwsEC2Container container); @Override SSHCredentials getSshCredentials(AwsEC2Container container); boolean isStarted(AwsEC2Container awsEC2Container); Map<String, Set<String>> getNetworkInterfaceToSecurityGroupsMap(String instanceId); boolean verifySecurityGroupIdsOfNetworkInterfaceMap(String instanceId, Map<String, Set<String>> originalSecurityGroups);  }### Answer:
@Test public void processInvalidGroups () { Map<String, String> vpcToSecurityGroupMap; Collection<String> validSecurityGroups = IntStream.range(0, 10).mapToObj(i -> randomUUID().toString()).collect(Collectors.toList()); String invalidSecurityGroup = randomUUID().toString(); String invalidVpc = randomUUID().toString(); validSecurityGroups.forEach(s -> { String vpc = randomUUID().toString(); String instanceId = randomUUID().toString(); doReturn(vpc).when(awsEC2Platform).getVpcIdOfContainer(instanceId); doReturn(s).when(awsEC2Platform).lookupChaosSecurityGroup(vpc); awsEC2Platform.getChaosSecurityGroupForInstance(instanceId); }); String instanceId = randomUUID().toString(); doReturn(invalidVpc).when(awsEC2Platform).getVpcIdOfContainer(instanceId); doReturn(invalidSecurityGroup).when(awsEC2Platform).lookupChaosSecurityGroup(invalidVpc); awsEC2Platform.getChaosSecurityGroupForInstance(instanceId); vpcToSecurityGroupMap = awsEC2Platform.getVpcToSecurityGroupMap(); Collection<String> expectedSecurityGroups = new ArrayList<>(validSecurityGroups); expectedSecurityGroups.add(invalidSecurityGroup); assertThat(vpcToSecurityGroupMap.values(), IsIterableContainingInAnyOrder.containsInAnyOrder(expectedSecurityGroups .toArray(new String[0]))); awsEC2Platform.processInvalidGroups(Collections.singleton(invalidSecurityGroup)); vpcToSecurityGroupMap = awsEC2Platform.getVpcToSecurityGroupMap(); assertThat(vpcToSecurityGroupMap.values(), IsIterableContainingInAnyOrder.containsInAnyOrder(validSecurityGroups .toArray(new String[0]))); }