-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
868f339
commit aeb8745
Showing
3 changed files
with
73 additions
and
8 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
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
57 changes: 57 additions & 0 deletions
57
...r/src/test/java/de/deadlocker8/budgetmaster/unit/transaction/csvimport/CsvParserTest.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,57 @@ | ||
package de.deadlocker8.budgetmaster.unit.transaction.csvimport; | ||
|
||
import com.opencsv.exceptions.CsvValidationException; | ||
import de.deadlocker8.budgetmaster.transactions.csvimport.CsvParser; | ||
import de.deadlocker8.budgetmaster.transactions.csvimport.CsvRow; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class CsvParserTest | ||
{ | ||
private static final String VALID_CSV = "Date;Title;Amount\n" + | ||
"03.01.2023;Lorem;50.00\n" + | ||
"05.01.2023;Ipsum;-8.37\n" + | ||
"08.01.2023;dolor sit amet;-12.00"; | ||
|
||
@Test | ||
void test_parseCsv_emptyFile() throws CsvValidationException, IOException | ||
{ | ||
assertThat(CsvParser.parseCsv("", ';', 0)) | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
void test_parseCsv_separatorNotPresent() throws CsvValidationException, IOException | ||
{ | ||
assertThat(CsvParser.parseCsv("abc,17", ';', 0)) | ||
.containsExactly(new CsvRow("abc,17")); | ||
} | ||
|
||
@Test | ||
void test_parseCsv() throws CsvValidationException, IOException | ||
{ | ||
assertThat(CsvParser.parseCsv(VALID_CSV, ';', 0)). | ||
containsExactly(new CsvRow("Date", "Title", "Amount"), | ||
new CsvRow("03.01.2023", "Lorem", "50.00"), | ||
new CsvRow("05.01.2023", "Ipsum", "-8.37"), | ||
new CsvRow("08.01.2023", "dolor sit amet", "-12.00")); | ||
} | ||
|
||
@Test | ||
void test_parseCsv_skipLines() throws CsvValidationException, IOException | ||
{ | ||
assertThat(CsvParser.parseCsv(VALID_CSV, ';', 2)). | ||
containsExactly(new CsvRow("05.01.2023", "Ipsum", "-8.37"), | ||
new CsvRow("08.01.2023", "dolor sit amet", "-12.00")); | ||
} | ||
|
||
@Test | ||
void test_parseCsv_skipLines_moreThanExisting() throws CsvValidationException, IOException | ||
{ | ||
assertThat(CsvParser.parseCsv(VALID_CSV, ';', 999)) | ||
.isEmpty(); | ||
} | ||
} |