-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some tests for CsvPrinter.java
- Loading branch information
1 parent
b8f061b
commit 0e726b7
Showing
2 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/src/test/java/de/jplag/reporting/csv/CsvPrinterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.jplag.reporting.csv; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CsvPrinterTest { | ||
private static final String EXPECTED_CSV_TEXT = "1,test1\r\n2,\"test2,\"\"x\"\"\"\r\n"; | ||
private static final List<CsvTestItem> TEST_ITEMS = List.of(new CsvTestItem(1, "test1"), new CsvTestItem(2, "test2,\"x\"")); | ||
|
||
@Test | ||
void testPrintWithReflectiveMapper() throws IOException { | ||
CsvDataMapper<CsvTestItem> mapper = new ReflectiveCsvDataMapper<>(CsvTestItem.class); | ||
CsvPrinter<CsvTestItem> printer = new CsvPrinter<>(mapper); | ||
|
||
printer.addRows(TEST_ITEMS); | ||
|
||
Assertions.assertEquals(EXPECTED_CSV_TEXT, printer.printToString()); | ||
} | ||
|
||
@Test | ||
void testPrintWithHardcodedMapper() throws IOException { | ||
CsvDataMapper<CsvTestItem> mapper = new HardcodedCsvDataMapper<>(2, item -> new Object[] {item.number(), item.text()}); | ||
CsvPrinter<CsvTestItem> printer = new CsvPrinter<>(mapper); | ||
|
||
printer.addRows(TEST_ITEMS); | ||
|
||
Assertions.assertEquals(EXPECTED_CSV_TEXT, printer.printToString()); | ||
} | ||
|
||
private record CsvTestItem(@CsvValue(1) int number, @CsvValue(2) String text) { | ||
} | ||
} |