Skip to content

Commit edd8d9b

Browse files
committed
Fix tests for Windows
1 parent 6895c27 commit edd8d9b

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

src/test/java/rife/bld/extension/junitreporter/JUnitXmlParserTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.jupiter.api.DisplayName;
2020
import org.junit.jupiter.api.Nested;
2121
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.condition.DisabledOnOs;
2223
import org.junit.jupiter.api.condition.EnabledOnOs;
2324
import org.junit.jupiter.api.condition.OS;
2425
import org.junit.jupiter.api.io.TempDir;
@@ -40,6 +41,7 @@
4041
import java.nio.file.Path;
4142
import java.util.Map;
4243

44+
import static java.io.File.separatorChar;
4345
import static org.assertj.core.api.Assertions.*;
4446
import static org.mockito.ArgumentMatchers.any;
4547
import static rife.bld.extension.junitreporter.JUnitXmlParser.EOL;
@@ -278,7 +280,7 @@ void extractTestFailuresGroupedWithInvalidTimeFormats(@TempDir Path tempDir) thr
278280

279281
@Test
280282
void extractTestFailuresGroupedWithInvalidXmlPath() {
281-
var invalidPath = "nonexistent/path/to/file.xml";
283+
var invalidPath = "nonexistent" + separatorChar + "file.xml";
282284

283285
assertThatThrownBy(() -> JUnitXmlParser.extractTestFailuresGrouped(invalidPath))
284286
.isInstanceOf(JUnitXmlParserException.class)
@@ -425,6 +427,7 @@ void extractTestFailuresGroupedWithNullTextContent(@TempDir Path tempDir) throws
425427
}
426428

427429
@Test
430+
@DisabledOnOs(OS.WINDOWS)
428431
void extractTestFailuresGroupedWithUnreadableFile(@TempDir Path tempDir) throws IOException {
429432
var tempFile = tempDir.resolve("test.xml");
430433
Files.createFile(tempFile);
@@ -1072,7 +1075,7 @@ void validateFileThrowsWhenFileDoesNotExist() {
10721075
}
10731076

10741077
@Test
1075-
@EnabledOnOs({OS.LINUX, OS.MAC})
1078+
@DisabledOnOs(OS.WINDOWS)
10761079
void validateFileThrowsWhenFileIsNotReadable(@TempDir Path tempDir) throws IOException {
10771080
var tempFile = tempDir.resolve("test.xml");
10781081
Files.createFile(tempFile);

src/test/java/rife/bld/extension/junitreporter/ReportPrinterTests.java

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,20 @@ void indentWithNullString(String input) {
178178
class PrintFailureTests {
179179
@Test
180180
void printFailureWithNullFailureIndex() {
181-
var failure = new TestFailure("testMethod", "Test Method", "TestClass", "AssertionError",
182-
"Test failed message", "", 0.123);
181+
var failure = new TestFailure("testMethod", "Test Method", "TestClass",
182+
"AssertionError", "Test failed message", "", 0.123);
183183

184184
var outContent = new ByteArrayOutputStream();
185185
System.setOut(new PrintStream(outContent));
186186

187187
ReportPrinter.printFailure(failure, 1, null);
188188

189-
var expectedOutput = """
190-
Test: testMethod
191-
- Name: Test Method
192-
- Type: AssertionError
193-
- Message:
194-
Test failed message
195-
- Time: 0.123
196-
""";
189+
var expectedOutput = String.format("Test: testMethod%n" +
190+
" - Name: Test Method%n" +
191+
" - Type: AssertionError%n" +
192+
" - Message:%n" +
193+
" Test failed message%n" +
194+
" - Time: 0.123%n");
197195

198196
assertThat(outContent.toString().trim()).isEqualTo(expectedOutput.trim());
199197

@@ -202,22 +200,20 @@ void printFailureWithNullFailureIndex() {
202200

203201
@Test
204202
void printFailureWithNullIndices() {
205-
var failure = new TestFailure("testMethod", "Test Method", "TestClass", "AssertionError",
206-
"Test failed message", "", 0.123);
203+
var failure = new TestFailure("testMethod", "Test Method", "TestClass",
204+
"AssertionError", "Test failed message", "", 0.123);
207205

208206
var outContent = new ByteArrayOutputStream();
209207
System.setOut(new PrintStream(outContent));
210208

211209
ReportPrinter.printFailure(failure, null, null);
212210

213-
var expectedOutput = """
214-
Test: testMethod
215-
- Name: Test Method
216-
- Type: AssertionError
217-
- Message:
218-
Test failed message
219-
- Time: 0.123
220-
""";
211+
var expectedOutput = String.format("Test: testMethod%n" +
212+
" - Name: Test Method%n" +
213+
" - Type: AssertionError%n" +
214+
" - Message:%n" +
215+
" Test failed message%n" +
216+
" - Time: 0.123%n");
221217

222218
assertThat(outContent.toString().trim()).isEqualTo(expectedOutput.trim());
223219

@@ -226,22 +222,20 @@ void printFailureWithNullIndices() {
226222

227223
@Test
228224
void printFailureWithValidIndices() {
229-
var failure = new TestFailure("testMethod", "Test Method", "TestClass", "AssertionError",
230-
"Test failed message", "", 0.123);
225+
var failure = new TestFailure("testMethod", "Test Method", "TestClass",
226+
"AssertionError", "Test failed message", "", 0.123);
231227

232228
var outContent = new ByteArrayOutputStream();
233229
System.setOut(new PrintStream(outContent));
234230

235231
ReportPrinter.printFailure(failure, 1, 2);
236232

237-
var expectedOutput = """
238-
[1.2] Test: testMethod
239-
- Name: Test Method
240-
- Type: AssertionError
241-
- Message:
242-
Test failed message
243-
- Time: 0.123
244-
""";
233+
var expectedOutput = String.format("[1.2] Test: testMethod%n" +
234+
" - Name: Test Method%n" +
235+
" - Type: AssertionError%n" +
236+
" - Message:%n" +
237+
" Test failed message%n" +
238+
" - Time: 0.123%n");
245239

246240
assertThat(outContent.toString().trim()).isEqualTo(expectedOutput.trim());
247241

@@ -325,10 +319,10 @@ void printSummaryWithEmptyGroupedFailures() {
325319
@Test
326320
@SuppressWarnings("ExtractMethodRecommender")
327321
void printSummaryWithNonEmptyGroupedFailures() {
328-
var failure1 = new TestFailure("testMethod1", "Test Method 1", "TestClass1", "AssertionError",
329-
"Message: Test failed 1", "", 0.101);
330-
var failure2 = new TestFailure("testMethod2", "", "TestClass1", "AssertionError",
331-
"Message: Test failed 2", "", 0.202);
322+
var failure1 = new TestFailure("testMethod1", "Test Method 1", "TestClass1",
323+
"AssertionError", "Message: Test failed 1", "", 0.101);
324+
var failure2 = new TestFailure("testMethod2", "", "TestClass1",
325+
"AssertionError", "Message: Test failed 2", "", 0.202);
332326

333327
var failuresForClass1 = new TestClassFailures("TestClass1");
334328
failuresForClass1.addFailure(failure1);

0 commit comments

Comments
 (0)