### Question:
JcloudsLocationSecurityGroupCustomizer extends BasicJcloudsLocationCustomizer { @Override public void customize(JcloudsLocation location, ComputeService computeService, Template template) { if (!computeService.getSecurityGroupExtension().isPresent()) { LOG.warn("Security group extension for {} absent; cannot configure security groups in context: {}", computeService, applicationId); } else if (template.getLocation() == null) { LOG.warn("No location has been set on {}; cannot configure security groups in context: {}", template, applicationId); } else { LOG.info("Configuring security groups on location {} in context {}", location, applicationId); setSecurityGroupOnTemplate(location, template, computeService.getSecurityGroupExtension().get()); } } protected  JcloudsLocationSecurityGroupCustomizer(String applicationId); protected  JcloudsLocationSecurityGroupCustomizer(String applicationId, Supplier<Cidr> sshCidrSupplier); static JcloudsLocationSecurityGroupCustomizer getInstance(String applicationId); static JcloudsLocationSecurityGroupCustomizer getInstance(Entity entity); JcloudsLocationSecurityGroupCustomizer setRetryExceptionPredicate(Predicate<Exception> predicate); JcloudsLocationSecurityGroupCustomizer setSshCidrSupplier(Supplier<Cidr> cidrSupplier); JcloudsLocationSecurityGroupCustomizer addPermissionsToLocation(final JcloudsMachineLocation location, IpPermission... permissions); JcloudsLocationSecurityGroupCustomizer addPermissionsToLocation(final JcloudsMachineLocation location, SecurityGroupDefinition securityGroupDefinition); JcloudsLocationSecurityGroupCustomizer addPermissionsToLocation(final JcloudsMachineLocation location, final Iterable<IpPermission> permissions); void removePermissionsFromLocation(final JcloudsMachineLocation location, final Iterable<IpPermission> permissions); @Override void customize(JcloudsLocation location, ComputeService computeService, Template template); String getBrooklynCidrBlock(); static Predicate<Exception> newAwsExceptionRetryPredicate();  }### Answer:
@Test public void testSecurityGroupAddedWhenJcloudsLocationCustomised() { Template template = mock(Template.class); TemplateOptions templateOptions = mock(TemplateOptions.class); when(template.getLocation()).thenReturn(location); when(template.getOptions()).thenReturn(templateOptions); SecurityGroup group = newGroup("id"); when(securityApi.createSecurityGroup(anyString(), eq(location))).thenReturn(group); JcloudsLocation jcloudsLocationA = new JcloudsLocation(MutableMap.of("deferConstruction", true)); JcloudsLocation jcloudsLocationB = new JcloudsLocation(MutableMap.of("deferConstruction", true)); customizer.customize(jcloudsLocationA, computeService, template); customizer.customize(jcloudsLocationB, computeService, template); verify(securityApi).createSecurityGroup(anyString(), eq(location)); verify(securityApi, times(4)).addIpPermission(any(IpPermission.class), eq(group)); verify(templateOptions, times(2)).securityGroups(anyString()); }