Skip to content

Commit

Permalink
#4: Added a test to verify that German locale works.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear committed Sep 20, 2024
1 parent d76ae9d commit 0c310ba
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/test/java/com/exasol/swqa/maven/SummarizerMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.time.Duration;
import java.time.Instant;
import java.util.Comparator;
import java.util.Locale;
import java.util.logging.Logger;
import java.util.stream.Stream;

Expand All @@ -38,6 +39,7 @@ class SummarizerMojoIT {
// We need the flattened version of the POM file in order to include the generated POM.
private static final Path PLUGIN_POM = Path.of(".flattened-pom.xml").toAbsolutePath();
private static final Path BASE_TEST_DIR = Paths.get("src/test/resources").toAbsolutePath();
public static final Duration MAX_EXECUTION_TIME = Duration.of(500, MILLIS);

private static MavenIntegrationTestEnvironment testEnvironment;

Expand All @@ -61,7 +63,7 @@ void testExtractPathCoverage(final int missed, final int covered, final String e
try {
createMetricsFile(siteDir, missed, covered);
// [itest -> qs~allowed-execution-time~1]
runMojoWithMaxAllowedExecutionDuration(baseTestDir, Duration.of(500, MILLIS));
runMojoWithMaxAllowedExecutionDuration(baseTestDir, MAX_EXECUTION_TIME);
assertThat(Files.readString(targetDir.resolve("metrics.json")), equalTo("""
{
"coverage" : %s
Expand All @@ -86,13 +88,15 @@ private static Path prepareSiteDir(Path targetDir) {

private static void deleteDirectoryRecursively(Path dir) throws IOException {
if (Files.exists(dir)) {
try(final Stream<Path> dirElements = Files.walk(dir)) {
try (final Stream<Path> dirElements = Files.walk(dir)) {
dirElements //
.map(Path::toFile)//
.sorted(Comparator.reverseOrder()) //
.forEach(file -> {
final boolean success = file.delete();
if (!success) { LOGGER.warning("Unable to delete directory entry: " + file);}
if (!success) {
LOGGER.warning("Unable to delete directory entry: " + file);
}
});
}
}
Expand Down Expand Up @@ -152,4 +156,26 @@ void testWhenIgnoreFailureIsSetThenMissingJaCoCoReportFileIsIgnored() {
assertThat(emptyProjectDir.resolve("metrics.json").toFile(), not(anExistingFile()));
});
}

@Test
void testNumberFormatInJsonCorrectWhenUsingGermanLocale() throws Exception {
final Locale previousLocale = Locale.getDefault();
final Path baseTestDir = BASE_TEST_DIR.resolve("project-with-coverage");
final Path targetDir = baseTestDir.resolve("target");
final Path siteDir = prepareSiteDir(targetDir);
try {
// The German number format uses a comma as decimal separator.
Locale.setDefault(Locale.GERMAN);
createMetricsFile(siteDir, 2, 1);
runMojoWithMaxAllowedExecutionDuration(baseTestDir, MAX_EXECUTION_TIME);
assertThat(Files.readString(targetDir.resolve("metrics.json")), equalTo("""
{
"coverage" : 33.3
}
"""));
} finally {
Locale.setDefault(previousLocale);
cleanUpSiteDir(siteDir);
}
}
}

0 comments on commit 0c310ba

Please sign in to comment.