CSVParser implements Iterable<CSVRecord>, Closeable { public static CSVParser parse(File file, final CSVFormat format) throws IOException { Args.notNull(file, "file"); Args.notNull(format, "format"); return new CSVParser(new FileReader(file), format); } CSVParser(final Reader reader, final CSVFormat format); static CSVParser parse(File file, final CSVFormat format); static CSVParser parse(String string, final CSVFormat format); static CSVParser parse(URL url, Charset charset, final CSVFormat format); void close(); long getCurrentLineNumber(); Map<String, Integer> getHeaderMap(); long getRecordNumber(); List<CSVRecord> getRecords(); boolean isClosed(); Iterator<CSVRecord> iterator();  }
@Test public void testForEach() throws Exception { final List<CSVRecord> records = new ArrayList<CSVRecord>(); final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); for (final CSVRecord record : CSVFormat.DEFAULT.parse(in)) { records.add(record); } assertEquals(3, records.size()); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(0).values()); assertArrayEquals(new String[]{"1", "2", "3"}, records.get(1).values()); assertArrayEquals(new String[]{"x", "y", "z"}, records.get(2).values()); }
@Test(expected = IllegalArgumentException.class) public void testParseNullFileFormat() throws Exception { CSVParser.parse((File) null, CSVFormat.DEFAULT); }
@Test(expected = IllegalArgumentException.class) public void testParseFileNullFormat() throws Exception { CSVParser.parse(new File(""), null); }
@Test(expected = IllegalArgumentException.class) public void testParseNullStringFormat() throws Exception { CSVParser.parse((String) null, CSVFormat.DEFAULT); }
@Test(expected = IllegalArgumentException.class) public void testParseStringNullFormat() throws Exception { CSVParser.parse("csv data", null); }
@Test(expected = IllegalArgumentException.class) public void testParseNullUrlCharsetFormat() throws Exception { CSVParser.parse(null, Charset.defaultCharset(), CSVFormat.DEFAULT); }
@Test(expected = IllegalArgumentException.class) public void testParserUrlNullCharsetFormat() throws Exception { CSVParser.parse(new URL("http: }
@Test(expected = IllegalArgumentException.class) public void testParseUrlCharsetNullFormat() throws Exception { CSVParser.parse(new URL("http: }