### Question:
RuleServiceImpl implements RuleService { @Override public String invokeRule(String ruleId, List<Map<String, Object>> ruleOptionalParams) { Rule ruleDetails = ruleRepository.findById(ruleId).get(); AWSLambda awsLambdaClient = amazonClient.getAWSLambdaClient(config.getRule().getLambda().getRegion()); String invocationId = AdminUtils.getReferenceId(); boolean invokeStatus = invokeRule(awsLambdaClient, ruleDetails, invocationId, ruleOptionalParams); if(invokeStatus) { return invocationId; } else { return null; } }  @Override List<Rule> getAllRulesByTargetType(String targetType); @Override List<RuleProjection> getAllRulesByTargetTypeName(String targetType); @Override List<RuleProjection> getAllRulesByTargetTypeAndNotInRuleIdList(final String targetType, final List<String> ruleIdList); @Override List<RuleProjection> getAllRulesByTargetTypeAndRuleIdList(final String targetType, final List<String> ruleIdList); @Override Rule getByRuleId(String ruleId); @Override Page<Rule> getRules(final String searchTerm, final int page, final int size); @Override Collection<String> getAllAlexaKeywords(); @Override Collection<String> getAllRuleIds(); @Override String createRule(final MultipartFile fileToUpload, final CreateUpdateRuleDetails ruleDetails, final String userId); @Override String updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId); @Override String invokeRule(String ruleId, List<Map<String, Object>> ruleOptionalParams); @Override String enableDisableRule(final String ruleId, final String action, final String userId); @Override Map<String, Object> invokeAllRules(List<String> ruleIds); boolean isRuleIdExits(String ruleId); @Override List<RuleCategory> getAllRuleCategories();  }### Answer:
@Test public void invokeRuleTest() throws Exception { Optional<Rule> rule = getRuleDetailsResponse(); when(ruleRepository.findById(anyString())).thenReturn(rule); List<Map<String, Object>> additionalRuleParams = Lists.newArrayList(); String referenceId = "S4FA"; mockStatic(AdminUtils.class); mockStatic(ByteBuffer.class); when(AdminUtils.getReferenceId()).thenReturn(referenceId); Map<String, Object> ruleParamDetails = Maps.newHashMap(); when(mapper.readValue(anyString(), any(TypeReference.class))).thenReturn(ruleParamDetails); when(mapper.writeValueAsString(any())).thenReturn("[]"); RuleProperty ruleProperty = buildRuleProperty(); when(config.getRule()).thenReturn(ruleProperty); ByteBuffer params = ByteBuffer.wrap(rule.get().getRuleParams().getBytes()); when(ByteBuffer.wrap(any())).thenReturn(params); when(awsLambdaClient.invoke(any())).thenReturn(invokeResult); when(invokeResult.getStatusCode()).thenReturn(200); when(invokeRequest.withFunctionName(anyString()).withPayload(any(ByteBuffer.class))).thenReturn(invokeRequest); assertThat(ruleService.invokeRule("ruleId123", additionalRuleParams), is("S4FA")); }
@Test public void invokeRuleCheckInvokeStatusFalseTest() throws Exception { Optional<Rule> rule = getRuleDetailsResponse(); when(ruleRepository.findById(anyString())).thenReturn(rule); List<Map<String, Object>> additionalRuleParams = Lists.newArrayList(); String referenceId = null; mockStatic(AdminUtils.class); mockStatic(ByteBuffer.class); when(AdminUtils.getReferenceId()).thenReturn(referenceId); RuleProperty ruleProperty = buildRuleProperty(); when(config.getRule()).thenReturn(ruleProperty); ByteBuffer params = ByteBuffer.wrap(rule.get().getRuleParams().getBytes()); when(ByteBuffer.wrap(any())).thenReturn(params); when(awsLambdaClient.invoke(any())).thenReturn(invokeResult); when(invokeResult.getStatusCode()).thenReturn(500); when(invokeRequest.withFunctionName(anyString()).withPayload(any(ByteBuffer.class))).thenReturn(invokeRequest); assertNull(ruleService.invokeRule("ruleId123", additionalRuleParams)); }