### Question:
CsvReader implements Closeable, Iterable<String[]> { @Override public void close() throws IOException { br.close(); } CsvReader(Reader reader);  CsvReader(Reader reader, int line);  CsvReader(Reader reader, CsvParser csvParser);  CsvReader(Reader reader, int line, CsvParser csvParser); List<String[]> readAll(); String[] readNext(); @Override void close(); @Override Iterator<String[]> iterator(); static final int DEFAULT_SKIP_LINES; }### Answer:
@Test public void canCloseReader() throws IOException { csvr.close(); }
@Test public void testIteratorFunctionalityWithRetainEscapeCharsFalse() throws IOException { CsvParser parser = new CsvParserBuilder().retainEscapeChars(false).build(); CsvReader cr = new CsvReader(new StringReader(lines), parser); String[][] expectedResult = new String[7][]; expectedResult[0] = new String[]{"a", "b", "c"}; expectedResult[1] = new String[]{"a", "b,b,b", "c"}; expectedResult[2] = new String[]{"", "", ""}; expectedResult[3] = new String[]{"a", "PO Box 123,\nKippax,ACT. 2615.\nAustralia", "d."}; expectedResult[4] = new String[]{"Glen \"\"The Man\"\" Smith", "Athlete", "Developer"}; expectedResult[5] = new String[]{"\"\"\"\"", "test"}; expectedResult[6] = new String[]{"a\nb", "b", "\nd", "e"}; int idx = 0; for (String[] line : cr) { String[] expectedLine = expectedResult[idx++]; assertArrayEquals(expectedLine, line); } cr.close(); }
@Test public void testIteratorFunctionalityWithRetainEscapeCharsFalseAndAlwaysQuoteOutput() throws IOException { CsvParser parser = new CsvParserBuilder(). retainEscapeChars(false). alwaysQuoteOutput(true). build(); CsvReader cr = new CsvReader(new StringReader(lines), parser); String[][] expectedResult = new String[7][]; expectedResult[0] = new String[]{"\"a\"", "\"b\"", "\"c\""}; expectedResult[1] = new String[]{"\"a\"", "\"b,b,b\"", "\"c\""}; expectedResult[2] = new String[]{"", "", ""}; expectedResult[3] = new String[]{"\"a\"", "\"PO Box 123,\nKippax,ACT. 2615.\nAustralia\"", "\"d.\""}; expectedResult[4] = new String[]{"\"Glen \"\"The Man\"\" Smith\"", "\"Athlete\"", "\"Developer\""}; expectedResult[5] = new String[]{"\"\"\"\"\"\"", "\"test\""}; expectedResult[6] = new String[]{"\"a\nb\"", "\"b\"", "\"\nd\"", "\"e\""}; int idx = 0; for (String[] line : cr) { String[] expectedLine = expectedResult[idx++]; assertArrayEquals(expectedLine, line); } cr.close(); }
@Test(expected = UnsupportedOperationException.class) public void quoteAndEscapeMustBeDifferent() throws IOException { StringBuilder sb = new StringBuilder(CsvParser.INITIAL_READ_SIZE); sb.append("a,b,c,ddd\\\"eee\nf,g,h,\"iii,jjj\""); CsvParser parser = new CsvParserBuilder(). quoteChar(CsvParser.DEFAULT_QUOTE_CHAR). escapeChar(CsvParser.DEFAULT_QUOTE_CHAR). build(); CsvReader cr = null; try { cr = new CsvReader(new StringReader(sb.toString()), parser); } finally { if (cr != null) { cr.close(); } } }