### Question:
RuleToXmlConverter implements RuleConverter { @Override public Rule unmarshal(String value) throws RuleConversionException { validateAgainstSchema(value); try { Unmarshaller unmarshaller = createUnmarshaller(); XMLInputFactory xmlInputFactory = getXmlInputFactory(); XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(value)); RuleSer ruleSer = ((JAXBElement<RuleSer>) unmarshaller.unmarshal(xmlStreamReader)).getValue(); return toRuleConverter.map(ruleSer); } catch (Exception e) { throw new RuleConversionException(String.format("Rule cannot be converted to Object:\n%s", value), e); } } private  RuleToXmlConverter(Class<?>... extraClasses); static RuleToXmlConverter getInstance(Class<?>... extraClasses); @Override String marshal(Rule rule); @Override Rule unmarshal(String value);  }### Answer:
@Test void shouldUnmarshalValidRuleWithBuildInObjectTypes() { Rule validRule = toRuleConverter.map(TestRuleFactory.constructValidRuleWithBuildInObjectTypes()); Rule ruleObject = converter.unmarshal(validXmlRuleWithBuildInObjectTypes); assertThat(ruleObject.getAttributes()).containsAll(validRule.getAttributes()); assertThat(ruleObject).isEqualTo(validRule); }
@Test void shouldUnmarshalValidRuleWithCustomObjectTypes() { Rule validRule = toRuleConverter.map(TestRuleFactory.constructValidRuleWithCustomObjectTypes()); Rule ruleObject = converter.unmarshal(validXmlRuleWithCustomObjectTypes); assertThat(ruleObject.getAttributes()).containsAll(validRule.getAttributes()); assertThat(ruleObject).isEqualTo(validRule); }
@Test void shouldUnmarshalValidRuleWithNullUndefinedValue() { Rule validRule = toRuleConverter.map(TestRuleFactory.constructValidRuleWithNullUndefinedValue()); Rule ruleObject = converter.unmarshal(validXmlRuleWithNullUndefinedValue); assertThat(ruleObject).isEqualTo(validRule); }
@Test void shouldUnmarshalValidRuleWithNullStringValue() { Rule validRule = toRuleConverter.map(TestRuleFactory.constructValidRuleWithNullStringValue()); Rule ruleObject = converter.unmarshal(validXmlRuleWithNullStringValue); assertThat(ruleObject).isEqualTo(validRule); }
@Test void shouldUnmarshalRuleConsistentWithSchema() { Rule ruleObject = converter.unmarshal(validXmlRuleWithBuildInObjectTypes); assertThat(ruleObject).isEqualTo(toRuleConverter.map(TestRuleFactory.constructValidRuleWithBuildInObjectTypes())); }
@Test @EnabledOnJre(JRE.JAVA_8) void shouldThrowExceptionWhenXmlRuleDoesNotSatisfySchemaOnJdk8() { String invalidXmlRule = "" + "<yare:Rule xmlns:yare=\"http: " <yare:unexpectedElement/>\n" + "</yare:Rule>"; assertThatThrownBy(() -> converter.unmarshal(invalidXmlRule)) .isInstanceOf(SchemaValidationException.class) .hasMessage("Given XML rule does not satisfy schema. Errors:\n" + "Line: 2. Column: 30. " + "Error: cvc-complex-type.2.4.a: Invalid content was found starting with element 'yare:unexpectedElement'. " + "One of '{\"http: "\"http: "\"http: "is expected."); }
@Test @DisabledOnJre(JRE.JAVA_8) void shouldThrowExceptionWhenXmlRuleDoesNotSatisfySchemaOnJdkDifferentThan8() { String invalidXmlRule = "" + "<yare:Rule xmlns:yare=\"http: " <yare:unexpectedElement/>\n" + "</yare:Rule>"; assertThatThrownBy(() -> converter.unmarshal(invalidXmlRule)) .isInstanceOf(SchemaValidationException.class) .hasMessage("Given XML rule does not satisfy schema. Errors:\n" + "Line: 2. Column: 30. " + "Error: cvc-complex-type.2.4.a: Invalid content was found starting with element '{\"http: "One of '{\"http: "\"http: "\"http: "is expected."); }