66import org .junit .jupiter .api .Disabled ;
77import org .junit .jupiter .params .ParameterizedTest ;
88import org .junit .jupiter .params .provider .MethodSource ;
9+ import org .xmlunit .assertj .XmlAssert ;
910import org .xmlunit .builder .Input ;
1011import org .xmlunit .validation .JAXPValidator ;
1112import org .xmlunit .validation .Languages ;
2021import java .nio .file .Files ;
2122import java .nio .file .Path ;
2223import java .nio .file .Paths ;
24+ import java .util .ArrayList ;
2325import java .util .Arrays ;
2426import java .util .Comparator ;
2527import java .util .List ;
2830import java .util .stream .Stream ;
2931
3032import static io .cucumber .junitxmlformatter .Jackson .OBJECT_MAPPER ;
33+ import static org .assertj .core .api .Assertions .assertThat ;
3134import static org .xmlunit .assertj .XmlAssert .assertThat ;
3235
3336class MessagesToJunitXmlWriterAcceptanceTest {
@@ -49,7 +52,7 @@ void test(TestCase testCase) throws IOException {
4952 ByteArrayOutputStream bytes = writeJunitXmlReport (testCase , new ByteArrayOutputStream ());
5053 Source expected = Input .fromPath (testCase .expected ).build ();
5154 Source actual = Input .fromByteArray (bytes .toByteArray ()).build ();
52- assertThat (actual ).and (expected ).ignoreWhitespace ().areIdentical ();
55+ XmlAssert . assertThat (actual ).and (expected ).ignoreWhitespace ().areIdentical ();
5356 }
5457
5558 @ ParameterizedTest
@@ -58,7 +61,7 @@ void validateAgainstJenkins(TestCase testCase) throws IOException {
5861 ByteArrayOutputStream bytes = writeJunitXmlReport (testCase , new ByteArrayOutputStream ());
5962 Source actual = Input .fromByteArray (bytes .toByteArray ()).build ();
6063 Source jenkinsSchema = Input .fromPath (Paths .get ("../jenkins-junit.xsd" )).build ();
61- assertThat (actual ).isValidAgainst (jenkinsSchema );
64+ XmlAssert . assertThat (actual ).isValidAgainst (jenkinsSchema );
6265 }
6366
6467 static final List <String > testCasesWithMissingException = Arrays .asList (
@@ -76,11 +79,16 @@ void validateAgainstSurefire(TestCase testCase) throws IOException {
7679 ByteArrayOutputStream bytes = writeJunitXmlReport (testCase , new ByteArrayOutputStream ());
7780 Source actual = Input .fromByteArray (bytes .toByteArray ()).build ();
7881 Source surefireSchema = Input .fromPath (Paths .get ("../surefire-test-report-3.0.xsd" )).build ();
79- if (!testCasesWithMissingException .contains (testCase .name )) {
80- assertThat (actual ).isValidAgainst (surefireSchema );
81- return ;
82- }
8382
83+ JAXPValidator validator = new JAXPValidator (Languages .W3C_XML_SCHEMA_NS_URI );
84+ validator .setSchemaSource (surefireSchema );
85+ ValidationResult validationResult = validator .validateInstance (actual );
86+
87+ List <String > expectedProblems = new ArrayList <>();
88+ /*
89+ * We add the timestamp attribute to all reports.
90+ */
91+ expectedProblems .add ("cvc-complex-type.3.2.2: Attribute 'timestamp' is not allowed to appear in element 'testsuite'." );
8492 /*
8593 This report tries to be compatible with the Jenkins XSD. The Surefire
8694 XSD is a bit stricter and generally assumes tests fail with an
@@ -94,12 +102,11 @@ void validateAgainstSurefire(TestCase testCase) throws IOException {
94102 Since the Surefire XSD is also relatively popular we do check it and
95103 exclude the cases that don't pass selectively.
96104 */
97- JAXPValidator validator = new JAXPValidator ( Languages . W3C_XML_SCHEMA_NS_URI );
98- validator . setSchemaSource ( surefireSchema );
99- ValidationResult validationResult = validator . validateInstance ( actual );
105+ if ( testCasesWithMissingException . contains ( testCase . name )) {
106+ expectedProblems . add ( "cvc-complex-type.4: Attribute 'type' must appear on element 'failure'." );
107+ }
100108 Iterable <ValidationProblem > problems = validationResult .getProblems ();
101- Assertions .assertThat (problems ).extracting (ValidationProblem ::getMessage )
102- .containsOnly ("cvc-complex-type.4: Attribute 'type' must appear on element 'failure'." );
109+ assertThat (problems ).extracting (ValidationProblem ::getMessage ).containsAll (expectedProblems );
103110 }
104111
105112 @ ParameterizedTest
0 commit comments