CsvExporter { public String export() { StringBuilder sb = new StringBuilder(); for (int row = 0; row < dataRows + 1; row++) { for (int col = 0; col < numCols; col++) { sb.append(dt.get(row, col)); if (col < numCols - 1) { sb.append(','); } else { sb.append('\n'); } } } return sb.toString(); } CsvExporter(int numCols, String... headers); void addRow(List<?> data); void addRow(Object... data); void clear(); String export();  }
@Test public void export() { exporter = new CsvExporter(2, "foo", "bar"); assertEquals("foo,bar\n", exporter.export()); exporter.addRow("hello", "world"); assertEquals("foo,bar\nhello,world\n", exporter.export()); exporter.clear(); assertEquals("foo,bar\n", exporter.export()); }