CsvRecordSource implements RecordSource { @Override public Iterable<Record> getRecords() throws Exception { return new Iterable<Record>() { @Override public Iterator<Record> iterator() { return new CsvRecordIterator(); } }; } CsvRecordSource(Reader reader, DateFormat dateFormat); @Override Header getHeader(); @Override Iterable<Record> getRecords(); @Override String getTimeAndLocationColumnDescription(); static Object[] toObjects(String[] textValues, Class<?>[] types);  }
@Test public void testBadCsvWithNoLat() throws Exception { final String CSV = "" + "\n" + "# Test CSV\n" + "\n" + "ID\tNoLAT\tLONG\tTIME\tSITE\tCHL\tFLAG\n" + "16\t53.1\t13.6\t2003-04-03 00:00:00\t\t0.5\t1\n" + "17\t53.3\t13.4\t2003-04-08 00:00:00\t\t\t\n" + "18\t53.1\t13.5\t2003-04-11 00:00:00\tA\t0.4\t\n"; try { CsvRecordSource recordSource = new CsvRecordSource(new StringReader(CSV), SHORT_DATE_FORMAT); Iterable<Record> records; records = recordSource.getRecords(); for (Record record : records) { record.getLocation(); } fail("error not detected"); } catch (Exception e) { assertEquals( "missing lat and lon columns in header of point data file (one of lat, latitude, northing and one of lon, long, longitude, easting expected)", e.getMessage()); } }
@Test public void testRealLifeCsvWithMalformedTime() throws Exception { try { final String url = this.getClass().getResource("/point-data-bad-time-format.txt").toExternalForm(); MAConfig maConfig = new MAConfig(); maConfig.setRecordSourceUrl(url); final RecordSource recordSource = maConfig.createRecordSource(new Configuration()); Iterable<Record> records = recordSource.getRecords(); for (Record record : records) { record.getTime(); } fail("error not detected"); } catch (Exception e) { assertEquals("time value '08.05.2006' in line 3 column 3 of point data file not well-formed (pattern yyyy-MM-dd HH:mm:ss expected)", e.getMessage()); } }