CSVLogger { public void writeLine(String[] values) throws IOException { int idx = 0; for (String value : values) { if (isIndexOfLastArrayElement(values, idx)) { writeLine(value); } else { write(value); } idx++; } }  void setFilename(String filename); String getFilename(); BufferedWriterManager getBufferedWriterManager(); void setBufferedWriterManager(BufferedWriterManager bufferedWriterManager); void setDelimiter(String delimiter); String getDelimiter(); void setNullString(String nullString); String getNullString(); void open(); void close(); void write(double value); void write(float value); void write(int value); void write(String string); void write(Date date); void writeLine(String[] values); void writeLine(String value); void writeLine(Date value); void writeLine(int value); void writeLine(float value); void writeLine(double value); @Override String toString(); static final String DEFAULT_DELIMITER; static final String DEFAULT_NULL_STRING; }
@Test public void writeLineWithDateShouldDelegateToWriter() throws Exception { givenCSVLoggerIsCreated(); givenWriterManagerReturnsWriterMock(); givenCSVLoggerIsOpen(); Date inputDate = new Date(); csvLogger.writeLine(inputDate); thenWriterShouldWriteLine("" + inputDate); }
@Test public void writeLineWithStringShouldDelegateToWriter() throws Exception { givenCSVLoggerIsCreated(); givenWriterManagerReturnsWriterMock(); givenCSVLoggerIsOpen(); String inputString = "TestString"; csvLogger.writeLine(inputString); thenWriterShouldWriteLine("" + inputString); }
@Test public void writeLineWithIntShouldDelegateToWriter() throws Exception { givenCSVLoggerIsCreated(); givenWriterManagerReturnsWriterMock(); givenCSVLoggerIsOpen(); int inputInt = 15; csvLogger.writeLine(inputInt); thenWriterShouldWriteLine("" + inputInt); }
@Test public void writeLineWithFloatShouldDelegateToWriter() throws Exception { givenCSVLoggerIsCreated(); givenWriterManagerReturnsWriterMock(); givenCSVLoggerIsOpen(); float inputFloat = 16.0f; csvLogger.writeLine(inputFloat); thenWriterShouldWriteLine("" + inputFloat); }
@Test public void writeLineWithDoubleShouldDelegateToWriter() throws Exception { givenCSVLoggerIsCreated(); givenWriterManagerReturnsWriterMock(); givenCSVLoggerIsOpen(); double inputDouble = 17.0; csvLogger.writeLine(inputDouble); thenWriterShouldWriteLine("" + inputDouble); }
@Test public void writeLineWithEmptyStringArrayShouldNotDelegateToWriter() throws Exception { givenCSVLoggerIsCreated(); givenWriterManagerReturnsWriterMock(); givenCSVLoggerIsOpen(); String[] emptyStringArray = {}; csvLogger.writeLine(emptyStringArray); thenWriterShouldNotBeWrittenTo(); }