Skip to content

Commit 817561f

Browse files
committed
Add test that documents behavior of multiple iterators over the same CSVParser.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1513228 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5a30b37 commit 817561f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,24 @@ public void testIterator() throws Exception {
488488
}
489489
}
490490

491+
@Test // TODO this may lead to strange behavior, throw an exception if iterator() has already been called?
492+
public void testMultipleIterators() throws Exception {
493+
CSVParser parser = CSVParser.parse("a,b,c" + CR + "d,e,f", CSVFormat.DEFAULT);
494+
495+
Iterator<CSVRecord> itr1 = parser.iterator();
496+
Iterator<CSVRecord> itr2 = parser.iterator();
497+
498+
CSVRecord first = itr1.next();
499+
assertEquals("a", first.get(0));
500+
assertEquals("b", first.get(1));
501+
assertEquals("c", first.get(2));
502+
503+
CSVRecord second = itr2.next();
504+
assertEquals("d", second.get(0));
505+
assertEquals("e", second.get(1));
506+
assertEquals("f", second.get(2));
507+
}
508+
491509
@Test
492510
public void testHeader() throws Exception {
493511
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");

0 commit comments

Comments
 (0)