|
19 | 19 | package org.apache.maven.plugin.failsafe;
|
20 | 20 |
|
21 | 21 | import java.io.File;
|
| 22 | +import java.nio.charset.StandardCharsets; |
| 23 | +import java.nio.file.Files; |
| 24 | +import java.nio.file.StandardOpenOption; |
| 25 | +import java.util.Locale; |
22 | 26 |
|
23 | 27 | import org.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils;
|
24 | 28 | import org.apache.maven.surefire.api.suite.RunResult;
|
25 | 29 | import org.apache.maven.surefire.api.util.SureFireFileManager;
|
26 | 30 | import org.junit.Test;
|
27 | 31 |
|
| 32 | +import static java.lang.String.format; |
28 | 33 | import static org.assertj.core.api.Assertions.assertThat;
|
29 | 34 |
|
30 | 35 | /**
|
@@ -64,6 +69,49 @@ public void testSkipped() throws Exception {
|
64 | 69 | writeReadCheck(new RunResult(3, 2, 1, 0, null, true));
|
65 | 70 | }
|
66 | 71 |
|
| 72 | + @Test |
| 73 | + public void testFlakes() throws Exception { |
| 74 | + writeReadCheck(new RunResult(3, 2, 1, 0, 2, null, true)); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testLegacyDeserialization() throws Exception { |
| 79 | + File legacySummary = SureFireFileManager.createTempFile("failsafe", "test"); |
| 80 | + String legacyFailsafeSummaryXmlTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 81 | + + "<failsafe-summary xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" |
| 82 | + + " xsi:noNamespaceSchemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/failsafe-summary.xsd\"" |
| 83 | + + " result=\"%s\" timeout=\"%s\">\n" |
| 84 | + + " <completed>%d</completed>\n" |
| 85 | + + " <errors>%d</errors>\n" |
| 86 | + + " <failures>%d</failures>\n" |
| 87 | + + " <skipped>%d</skipped>\n" |
| 88 | + + " %s\n" |
| 89 | + + "</failsafe-summary>"; |
| 90 | + String xml = format(Locale.ROOT, legacyFailsafeSummaryXmlTemplate, 0, false, 3, 2, 1, 0, "msg"); |
| 91 | + Files.write( |
| 92 | + legacySummary.toPath(), |
| 93 | + xml.getBytes(StandardCharsets.UTF_8), |
| 94 | + StandardOpenOption.CREATE, |
| 95 | + StandardOpenOption.TRUNCATE_EXISTING, |
| 96 | + StandardOpenOption.WRITE); |
| 97 | + |
| 98 | + // When the failsafe-summary.xml does not contain the <flakes> element, it should be considered as 0. |
| 99 | + RunResult expected = new RunResult(3, 2, 1, 0, 0, null, false); |
| 100 | + RunResult actual = FailsafeSummaryXmlUtils.toRunResult(legacySummary); |
| 101 | + |
| 102 | + assertThat(actual.getCompletedCount()).isEqualTo(expected.getCompletedCount()); |
| 103 | + |
| 104 | + assertThat(actual.getErrors()).isEqualTo(expected.getErrors()); |
| 105 | + |
| 106 | + assertThat(actual.getFailures()).isEqualTo(expected.getFailures()); |
| 107 | + |
| 108 | + assertThat(actual.getSkipped()).isEqualTo(expected.getSkipped()); |
| 109 | + |
| 110 | + assertThat(actual.getFlakes()).isEqualTo(expected.getFlakes()); |
| 111 | + |
| 112 | + assertThat(actual).isEqualTo(expected); |
| 113 | + } |
| 114 | + |
67 | 115 | @Test
|
68 | 116 | public void testAppendSerialization() throws Exception {
|
69 | 117 | RunResult simpleAggregate = getSimpleAggregate();
|
|
0 commit comments