From 817561f4d78b0f8b967039e86c286d3faa175d13 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Mon, 12 Aug 2013 19:23:16 +0000 Subject: [PATCH] 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 --- .../org/apache/commons/csv/CSVParserTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index b461ec4f..7e094793 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -488,6 +488,24 @@ public class CSVParserTest { } } + @Test // TODO this may lead to strange behavior, throw an exception if iterator() has already been called? + public void testMultipleIterators() throws Exception { + CSVParser parser = CSVParser.parse("a,b,c" + CR + "d,e,f", CSVFormat.DEFAULT); + + Iterator itr1 = parser.iterator(); + Iterator itr2 = parser.iterator(); + + CSVRecord first = itr1.next(); + assertEquals("a", first.get(0)); + assertEquals("b", first.get(1)); + assertEquals("c", first.get(2)); + + CSVRecord second = itr2.next(); + assertEquals("d", second.get(0)); + assertEquals("e", second.get(1)); + assertEquals("f", second.get(2)); + } + @Test public void testHeader() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");