### Question:
UnusedElasticIpRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) { logger.debug("========UnusedElasticIpRule started========="); Annotation annotation = null; String associationId = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String,Object>>issueList = new ArrayList<>(); LinkedHashMap<String,Object>issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(severity,category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { associationId = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.ASSOCIATION_ID)); if (StringUtils.isNullOrEmpty(associationId)) { annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"Unused Elastic Ip found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.SUBTYPE, Annotation.Type.RECOMMENDATION.toString()); annotation.put(PacmanRuleConstants.CATEGORY, category); annotation.put(PacmanRuleConstants.ALLOCATION_ID, resourceAttributes.get(PacmanRuleConstants.ALLOCATION_ID)); issue.put(PacmanRuleConstants.VIOLATION_REASON, "ElasticIp doesn't associated to an EC2 instance!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========UnusedElasticIpRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========UnusedElasticIpRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes); String getHelpText();  }### Answer:
@Test public void executeTest() throws Exception { mockStatic(PacmanUtils.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn( true); when(PacmanUtils.formatUrl(anyObject(),anyString())).thenReturn("host"); assertThat(unusedElasticIpRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")), is(notNullValue())); assertThat(unusedElasticIpRule.execute(CommonTestUtils.getAnotherMapString("r_123 "),CommonTestUtils.getAnotherMapString("r_123 ")), is(notNullValue())); when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn( false); assertThatThrownBy( () -> unusedElasticIpRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); }