### Question:
SecurityGroupRequestToSecurityGroupConverter implements Converter<SecurityGroupRequest, SecurityGroup> { @Override public SecurityGroup convert(@Nonnull SecurityGroupRequest source) { SecurityGroup entity = new SecurityGroup(); entity.setName(missingResourceNameGenerator.generateName(APIResourceType.SECURITY_GROUP)); entity.setSecurityGroupIds(convertSecurityGroupIdsToList(source)); entity.setSecurityRules(convertSecurityRules(source.getSecurityRules(), entity)); return entity; }  @Override SecurityGroup convert(@Nonnull SecurityGroupRequest source);  }### Answer:
@Test public void testConvertWithNullSecurityRulesAndNullGroupIds() { SecurityGroupRequest securityGroupRequest = new SecurityGroupRequest(); securityGroupRequest.setSecurityRules(null); securityGroupRequest.setSecurityGroupIds(null); SecurityGroup result = underTest.convert(securityGroupRequest); assertNotNull(result.getSecurityGroupIds()); assertTrue(result.getSecurityGroupIds().isEmpty()); assertNotNull(result.getSecurityRules()); assertTrue(result.getSecurityRules().isEmpty()); }
@Test public void testConvertWithEmptySecurityRulesAndProvidedGroupIds() { SecurityGroupRequest securityGroupRequest = new SecurityGroupRequest(); securityGroupRequest.setSecurityGroupIds(Set.of("sg-1", "sg-2")); securityGroupRequest.setSecurityRules(List.of()); SecurityGroup result = underTest.convert(securityGroupRequest); assertNotNull(result.getSecurityGroupIds()); assertEquals(2, result.getSecurityGroupIds().size()); assertNotNull(result.getSecurityRules()); assertTrue(result.getSecurityRules().isEmpty()); }
@Test public void testConvertWithSecurityRulesAndEmptyGroupIds() { SecurityGroupRequest securityGroupRequest = new SecurityGroupRequest(); SecurityRuleRequest ruleRequest = new SecurityRuleRequest(); ruleRequest.setModifiable(false); ruleRequest.setPorts(List.of("22")); ruleRequest.setProtocol("tcp"); ruleRequest.setSubnet("0.0.0.0/0"); securityGroupRequest.setSecurityRules(List.of(ruleRequest)); securityGroupRequest.setSecurityGroupIds(Set.of()); SecurityRule securityRule = new SecurityRule(); securityRule.setCidr("0.0.0.0/0"); securityRule.setProtocol("tcp"); securityRule.setPorts("22"); securityRule.setModifiable(false); when(securityRuleConverter.convert(ruleRequest)).thenReturn(securityRule); SecurityGroup result = underTest.convert(securityGroupRequest); assertNotNull(result.getSecurityGroupIds()); assertTrue(result.getSecurityGroupIds().isEmpty()); assertNotNull(result.getSecurityRules()); assertEquals(1, result.getSecurityRules().size()); assertEquals(securityRule, result.getSecurityRules().iterator().next()); }