CSVLogger { @Override public String toString() { if (file != null) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm"); Date lastModifiedDate = new Date(file.lastModified()); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("CSV "); stringBuilder.append("File [").append(file.getPath()).append("], "); stringBuilder.append("last modfied at [").append(dateFormat.format(lastModifiedDate) + "], "); stringBuilder.append("size [").append(file.length()).append(" bytes]."); return stringBuilder.toString(); } else { return "CSV File not opened yet."; } }  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 toStringOnOpenedLoggerShouldReturnStringContainingFileInformation() throws Exception { givenCSVLoggerIsCreated(); givenWriterManagerReturnsWriterMock(); givenCSVLoggerIsOpen(); givenFileExists(); String expectedToString = "CSV File [" + testFileManager.getTestFileName() + "], last modfied at [" + testFileManager.getLastModifiedTimestampOfTestFileAsString() + "], size [" + testFileManager.getLengthOfTestFile() + " bytes]."; assertThat(csvLogger.toString(), is(expectedToString)); }
@Test public void toStringOnUnopenedLoggerShouldNotThrowNullPointerException() throws Exception { String expectedToString = "CSV File not opened yet."; String actualToString = new CSVLogger().toString(); assertThat(actualToString, is(expectedToString)); }