### Question:
MVELRuleFactory extends AbstractRuleFactory { public Rule createRule(Reader ruleDescriptor) throws Exception { List<RuleDefinition> ruleDefinitions = reader.read(ruleDescriptor); if (ruleDefinitions.isEmpty()) { throw new IllegalArgumentException("rule descriptor is empty"); } return createRule(ruleDefinitions.get(0)); } MVELRuleFactory(RuleDefinitionReader reader);  MVELRuleFactory(RuleDefinitionReader reader, ParserContext parserContext); Rule createRule(Reader ruleDescriptor); Rules createRules(Reader rulesDescriptor);  }### Answer:
@Test public void testRuleCreationFromFileReader_withNonCompositeRuleDeclaresComposingRules() { File rulesDescriptor = new File("src/test/resources/non-composite-rule-with-composing-rules." + fileExtension); Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Non-composite rules cannot have composing rules"); }
@Test public void testRuleCreationFromFileReader() throws Exception { Reader adultRuleDescriptorAsReader = new FileReader("src/test/resources/adult-rule." + fileExtension); Rule adultRule = factory.createRule(adultRuleDescriptorAsReader); assertThat(adultRule.getName()).isEqualTo("adult rule"); assertThat(adultRule.getDescription()).isEqualTo("when age is greater than 18, then mark as adult"); assertThat(adultRule.getPriority()).isEqualTo(1); }
@Test public void testRuleCreationFromStringReader() throws Exception { Path ruleDescriptor = Paths.get("src/test/resources/adult-rule." + fileExtension); Reader adultRuleDescriptorAsReader = new StringReader(new String(Files.readAllBytes(ruleDescriptor))); Rule adultRule = factory.createRule(adultRuleDescriptorAsReader); assertThat(adultRule.getName()).isEqualTo("adult rule"); assertThat(adultRule.getDescription()).isEqualTo("when age is greater than 18, then mark as adult"); assertThat(adultRule.getPriority()).isEqualTo(1); }
@Test public void testRuleCreationFromFileReader_withInvalidCompositeRuleType() { File rulesDescriptor = new File("src/test/resources/composite-rule-invalid-composite-rule-type." + fileExtension); Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Invalid composite rule type, must be one of [UnitRuleGroup, ConditionalRuleGroup, ActivationRuleGroup]"); }
@Test public void testRuleCreationFromFileReader_withEmptyComposingRules() { File rulesDescriptor = new File("src/test/resources/composite-rule-invalid-empty-composing-rules." + fileExtension); Assertions.assertThatThrownBy(() -> factory.createRule(new FileReader(rulesDescriptor))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Composite rules must have composing rules specified"); }