Skip to content

Commit

Permalink
Set charset to UTF8 when writing to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed Feb 18, 2024
1 parent 97210aa commit 76c7b1a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/endava/cats/report/TestCaseExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -198,7 +199,7 @@ private void writeExecutionTimesForPathAndHttpMethod(String key, List<CatsTestCa
logger.noFormat(" ");
}
try {
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), EXECUTION_TIME_REPORT), maskingSerializer.toJson(timeExecutionDetails));
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), EXECUTION_TIME_REPORT), maskingSerializer.toJson(timeExecutionDetails), StandardCharsets.UTF_8);
} catch (IOException e) {
logger.warning("There was an issue writing the execution_times.js: {}. Please check if CATS has proper right to write in the report location: {}",
e.getMessage(), reportingPath.toFile().getAbsolutePath());
Expand Down Expand Up @@ -251,8 +252,8 @@ public void writeSummary(List<CatsTestCaseSummary> summaries, ExecutionStatistic

try {
writer.flush();
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), this.getSummaryReportTitle()), writer.toString());
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), REPORT_JS), maskingSerializer.toJson(report));
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), this.getSummaryReportTitle()), writer.toString(), StandardCharsets.UTF_8);
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), REPORT_JS), maskingSerializer.toJson(report), StandardCharsets.UTF_8);
} catch (IOException e) {
logger.error("There was an error writing the report summary: {}. Please check if CATS has proper right to write in the report location: {}",
e.getMessage(), reportingPath.toFile().getAbsolutePath());
Expand Down Expand Up @@ -325,7 +326,7 @@ public void writeTestCase(CatsTestCase testCase) {
private void writeJsonTestCase(CatsTestCase testCase) {
String testFileName = testCase.getTestId().replace(" ", "").concat(JSON);
try {
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), testFileName), maskingSerializer.toJson(testCase));
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), testFileName), maskingSerializer.toJson(testCase), StandardCharsets.UTF_8);
} catch (IOException e) {
logger.error("There was a problem writing test case {}: {}. Please check if CATS has proper right to write in the report location: {}",
testCase.getTestId(), e.getMessage(), reportingPath.toFile().getAbsolutePath());
Expand All @@ -345,7 +346,7 @@ private void writeHtmlTestCase(CatsTestCase testCase) {
Writer writer = TEST_CASE_MUSTACHE.execute(stringWriter, context);
String testFileName = testCase.getTestId().replace(" ", "").concat(HTML);
try {
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), testFileName), writer.toString());
Files.writeString(Paths.get(reportingPath.toFile().getAbsolutePath(), testFileName), writer.toString(), StandardCharsets.UTF_8);
} catch (IOException e) {
logger.error("There was a problem writing test case {}: {}. Please check if CATS has proper right to write in the report location: {}",
testCase.getTestId(), e.getMessage(), reportingPath.toFile().getAbsolutePath());
Expand Down

0 comments on commit 76c7b1a

Please sign in to comment.