Skip to content

Commit

Permalink
Merge pull request #6 from k3b/ImportCsv
Browse files Browse the repository at this point in the history
SecUSo#51: created failing unittest
  • Loading branch information
MaxIsV authored Feb 8, 2023
2 parents 54eb9f0 + d644fbd commit 5d77c3e
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public void readCsv() throws CsvValidationException, IOException {
// date,amount,note,category,account
String csvData = "date;amount;note;category;account\n" +
"1999-12-31;0.05;My Test Transaction;my test category;my test account";
StringReader csvDataReader = new StringReader(csvData);

CsvImporter importer = new CsvImporter(csvDataReader);
CsvImporter importer = createImporter(csvData);

List<Transaction> transactions = importer.readFromCsv();
assertNotNull("contains data", transactions);
Expand All @@ -48,7 +46,7 @@ public void readCsv() throws CsvValidationException, IOException {

@Test
public void testGetColumnNo_found() {
CsvImporter importer = new CsvImporter(new StringReader(""));
CsvImporter importer = createImporter("");

int columnNo = importer.getColumnNo(CsvDefinitions.CSV_HEADER_TRANSACTIONSSTRINGS, "note");
assertEquals(2, columnNo);
Expand All @@ -57,10 +55,27 @@ public void testGetColumnNo_found() {

@Test
public void testGetColumnNo_notFound() {
CsvImporter importer = new CsvImporter(new StringReader(""));
CsvImporter importer = createImporter("");

int columnNo = importer.getColumnNo(CsvDefinitions.CSV_HEADER_TRANSACTIONSSTRINGS, "doesNotExist");
assertEquals(-1, columnNo);

}

@Test
public void getColumnContent() {
String[] data = new String[]{"zero","one"};
CsvImporter importer = createImporter("");

assertEquals("1", "one",importer.getColumnContent(data,1));
assertEquals("-1",null,importer.getColumnContent(data,-1));
assertEquals("2",null,importer.getColumnContent(data,2));
}

private CsvImporter createImporter(String csvData) {
StringReader csvDataReader = new StringReader(csvData);

CsvImporter importer = new CsvImporter(csvDataReader);
return importer;
}
}

0 comments on commit 5d77c3e

Please sign in to comment.