### Question:
RuleServiceImpl implements RuleService { @Override public String createRule(final MultipartFile fileToUpload, final CreateUpdateRuleDetails ruleDetails, final String userId) throws PacManException { checkRuleTypeNotServerlessOrManaged(ruleDetails, fileToUpload); return addRuleInstance(fileToUpload, ruleDetails, userId); }  @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 createRuleTest() throws Exception { CreateUpdateRuleDetails createRuleDetails = getCreateUpdateRuleDetailsRequest(); MultipartFile firstFile = getMockMultipartFile(); Map<String, Object> ruleParamDetails = Maps.newHashMap(); List<Map<String, Object>> params = Lists.newArrayList(); Map<String, Object> param = Maps.newHashMap(); param.put("name", "name123"); param.put("value", "name123"); param.put("encrypt", true); params.add(param); param = Maps.newHashMap(); param.put("name", "name123"); param.put("value", "name123"); param.put("encrypt", false); param.put("isValueNew", true); params.add(param); ruleParamDetails.put("environmentVariables", params); ruleParamDetails.put("params", params); when(mapper.readValue(anyString(), any(TypeReference.class))).thenReturn(ruleParamDetails); when(mapper.writeValueAsString(any())).thenReturn("[]"); Optional<Rule> rule = getRuleDetailsResponse(); RuleProperty ruleProperty = buildRuleProperty(); when(config.getRule()).thenReturn(ruleProperty); when(ruleRepository.save(rule.get())).thenReturn(rule.get()); mockStatic(ByteBuffer.class); mockStatic(RuleState.class); when(amazonCloudWatchEvents.putRule(any())).thenReturn(putRuleResult); String ruleArn = "ruleArn123"; when(putRuleResult.getRuleArn()).thenReturn(ruleArn); when(amazonCloudWatchEvents.putTargets(any())).thenReturn(putTargetsResult); ByteBuffer byteBuffer = ByteBuffer.wrap(createRuleDetails.getRuleParams().getBytes()); when(ByteBuffer.wrap(any())).thenReturn(byteBuffer); when(awsLambdaClient.invoke(any())).thenReturn(invokeResult); when(awsLambdaClient.getPolicy(any())).thenReturn(getPolicyResult); when(invokeResult.getStatusCode()).thenReturn(200); when(invokeRequest.withFunctionName(anyString()).withPayload(any(ByteBuffer.class))).thenReturn(invokeRequest); int count = 0; when(putTargetsResult.getFailedEntryCount()).thenReturn(count); assertThat(ruleService.createRule(firstFile, createRuleDetails, "userId123"), is(String.format(AdminConstants.RULE_CREATION_SUCCESS))); }