Exporter { public abstract void export(Iterable<Map<String, V>> data); Exporter(OutputStream output);  Exporter(OutputStream output, Function<V, String> toStringFunction); abstract void export(Iterable<Map<String, V>> data);  }
@Test public void outputTest() { List<Map<String, Object>> stuff = ImmutableList.of( ImmutableMap.of("a", "1", "b", 2), ImmutableMap.of("b", 2, "c", 3, "d", 4), ImmutableMap.of("a", ImmutableList.of(1, 2, 3))); ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream stream = new PrintStream(out); Exporters.csv(stream).export(stuff); StringBuilder expected = new StringBuilder(); expected.append("a,b,c,d").append(System.lineSeparator()) .append("1,2,null,null").append(System.lineSeparator()) .append("null,2,3,4").append(System.lineSeparator()) .append("\"1,2,3\",null,null,null"); Assert.assertEquals(expected.toString(), out.toString()); }