When using opencsv with annotation and StatefulBeanToCsv, headers are not written when bean list is empty. I would assume this test successful but it's not.
private class bean1 {
@CsvBindByName(column = "column1")
private String col1;
public String getCol1() {
return col1;
}
public void setCol1(String col1) {
this.col1 = col1;
}
}
@Test
public void testOpenCsvEmptyBeanList() throws CsvException {
StringWriter sw = new StringWriter();
StatefulBeanToCsv<bean1> sbc = new StatefulBeanToCsvBuilder<bean1>(sw)
.withLineEnd(CSVWriter.DEFAULT_LINE_END)
.build();
// empty bean list
sbc.write(new ArrayList<>());
assertEquals("column1" + CSVWriter.DEFAULT_LINE_END, sw.toString());
}
Any idea to make this test works ?