Skip to content

Commit debc03e

Browse files
Added test to ensure only UTF-8 charaters are emitted
1 parent 4a2807e commit debc03e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎report/src/test/java/org/hjug/refactorfirst/report/ReportWriterTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.File;
77
import java.io.IOException;
8+
import java.nio.charset.StandardCharsets;
89
import java.nio.file.Files;
910
import java.nio.file.Path;
1011
import java.nio.file.StandardWatchEventKinds;
@@ -279,4 +280,20 @@ void containReportDirectory_rejectsSymlinkedAncestor(@TempDir Path tempDir) thro
279280
IllegalArgumentException.class,
280281
() -> ReportWriter.containReportDirectory(tempDir.toFile(), "linked/site"));
281282
}
283+
284+
@Test
285+
void writeReportToDisk_emitsUtf8ForNonAsciiContent(@TempDir Path tempDir) throws IOException {
286+
String nonAsciiContent = "café 漢字 😀";
287+
Path outputDir = tempDir.resolve("output");
288+
Files.createDirectories(outputDir);
289+
290+
ReportWriter.writeReportToDisk(outputDir.toString(), "test.html", nonAsciiContent);
291+
292+
Path outputFile = outputDir.resolve("test.html");
293+
assertTrue(Files.exists(outputFile));
294+
295+
byte[] writtenBytes = Files.readAllBytes(outputFile);
296+
byte[] expectedBytes = nonAsciiContent.getBytes(StandardCharsets.UTF_8);
297+
assertArrayEquals(expectedBytes, writtenBytes, "ReportWriter must emit UTF-8 bytes");
298+
}
282299
}

0 commit comments

Comments
 (0)