diff --git a/contribs/application/src/test/java/org/matsim/application/options/CsvOptionsTest.java b/contribs/application/src/test/java/org/matsim/application/options/CsvOptionsTest.java index 65299cb0e81..76d893dbd52 100644 --- a/contribs/application/src/test/java/org/matsim/application/options/CsvOptionsTest.java +++ b/contribs/application/src/test/java/org/matsim/application/options/CsvOptionsTest.java @@ -3,11 +3,13 @@ import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -20,18 +22,27 @@ public class CsvOptionsTest { @Test void output() throws IOException { - CsvOptions csv = new CsvOptions(CSVFormat.Predefined.TDF); + List delimiters = new ArrayList<>(); - Path tmp = f.resolve("test.csv"); + delimiters.add(new CsvOptions(CSVFormat.Predefined.TDF)); + delimiters.add(new CsvOptions(CSVFormat.Predefined.Default)); + delimiters.add(new CsvOptions(CSVFormat.Predefined.Default, ';', StandardCharsets.UTF_8)); - CSVPrinter printer = csv.createPrinter(tmp); + for (CsvOptions csv : delimiters) { + Path tmp = f.resolve("test.csv"); - printer.printRecord("header", "column"); - printer.printRecord("1", "2"); - printer.close(); + CSVPrinter printer = csv.createPrinter(tmp); - assertThat(tmp) - .hasContent("header\tcolumn\n1\t2"); + String delimiter = csv.getFormat().getDelimiterString(); + printer.printRecord("header", "column"); + printer.printRecord("1", "2"); + printer.close(); + + assertThat(tmp) + .hasContent("header" + delimiter + "column\n1" + delimiter + "2"); + + assertThat(delimiter).isEqualTo(csv.detectDelimiter(tmp.toString()).toString()); + } } }