@Test public void example1_can_be_read_with_3_columns_and_1_header_and_contains_expected_data() throws Exception { File file = DeveloperToolsTestFileSupport.getTestfileSupport().createFileFromResourcePath("csv/example1-developer-admin-ui_mass-import_projects.csv"); List<CSVRow> importedRows = importerToTest.importCSVFile(file, 3, 1); assertEquals(15, importedRows.size()); assertEquals("testproject_1", importedRows.get(0).columns.get(0).cell); assertEquals("scenario2_owner1", importedRows.get(11).columns.get(1).cell); assertEquals("scenario2_user1,scenario2_user2", importedRows.get(11).columns.get(2).cell); assertEquals("testproject_15", importedRows.get(14).columns.get(0).cell); assertEquals("scenario2_owner1", importedRows.get(14).columns.get(1).cell); assertEquals("scenario2_user4", importedRows.get(14).columns.get(2).cell); }
public List<CSVRow> importCSVFile(File file, int expectedColumnCount, int headlines) throws IOException { List<CSVRow> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader(file));) { String line = null; int lineNr=0; while ((line = br.readLine()) != null) { lineNr++; CSVRow row = CSVRow.importRow(line); int columnCount = row.columns.size(); if (columnCount!=expectedColumnCount) { throw new IllegalStateException("Expected "+expectedColumnCount+" but got "+columnCount+" in line:"+lineNr); } if (lineNr>headlines) { list.add(row); } } } return list; }
SimpleCSVImporter { public List<CSVRow> importCSVFile(File file, int expectedColumnCount, int headlines) throws IOException { List<CSVRow> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader(file));) { String line = null; int lineNr=0; while ((line = br.readLine()) != null) { lineNr++; CSVRow row = CSVRow.importRow(line); int columnCount = row.columns.size(); if (columnCount!=expectedColumnCount) { throw new IllegalStateException("Expected "+expectedColumnCount+" but got "+columnCount+" in line:"+lineNr); } if (lineNr>headlines) { list.add(row); } } } return list; } }
SimpleCSVImporter { public List<CSVRow> importCSVFile(File file, int expectedColumnCount, int headlines) throws IOException { List<CSVRow> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader(file));) { String line = null; int lineNr=0; while ((line = br.readLine()) != null) { lineNr++; CSVRow row = CSVRow.importRow(line); int columnCount = row.columns.size(); if (columnCount!=expectedColumnCount) { throw new IllegalStateException("Expected "+expectedColumnCount+" but got "+columnCount+" in line:"+lineNr); } if (lineNr>headlines) { list.add(row); } } } return list; }  }
SimpleCSVImporter { public List<CSVRow> importCSVFile(File file, int expectedColumnCount, int headlines) throws IOException { List<CSVRow> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader(file));) { String line = null; int lineNr=0; while ((line = br.readLine()) != null) { lineNr++; CSVRow row = CSVRow.importRow(line); int columnCount = row.columns.size(); if (columnCount!=expectedColumnCount) { throw new IllegalStateException("Expected "+expectedColumnCount+" but got "+columnCount+" in line:"+lineNr); } if (lineNr>headlines) { list.add(row); } } } return list; }  List<CSVRow> importCSVFile(File file, int expectedColumnCount, int headlines); }
SimpleCSVImporter { public List<CSVRow> importCSVFile(File file, int expectedColumnCount, int headlines) throws IOException { List<CSVRow> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader(file));) { String line = null; int lineNr=0; while ((line = br.readLine()) != null) { lineNr++; CSVRow row = CSVRow.importRow(line); int columnCount = row.columns.size(); if (columnCount!=expectedColumnCount) { throw new IllegalStateException("Expected "+expectedColumnCount+" but got "+columnCount+" in line:"+lineNr); } if (lineNr>headlines) { list.add(row); } } } return list; }  List<CSVRow> importCSVFile(File file, int expectedColumnCount, int headlines);  }