### Question:
FileNameSuffixFormatter { public String format(Document document) { requireNonNull(document, "Can not format file name suffix: input document is null!"); if (isBlank(document.getString(columnName))) throw new IllegalArgumentException("The specified document does not have a column " + columnName + " or it's value is blank!"); return format(document.getString(columnName)); } FileNameSuffixFormatter(String columnName, String dateTimeFormat); static FileNameSuffixFormatter from(ArchivingProperties properties); String format(Document document); String format(String value); static final DateTimeFormatter SOLR_DATETIME_FORMATTER; }### Answer:
@Test(expected = NullPointerException.class) public void testFormatWhenDocumentIsNullThrowingException() throws Exception { formatter.format((Document) null); }
@Test(expected = IllegalArgumentException.class) public void testFormatWhenSpecifiedColumnDoesNotExistsInTheDocumentThrowingException() throws Exception { formatter.format(new Document(new HashMap<>())); }
@Test(expected = IllegalArgumentException.class) public void testFormatWhenSpecifiedColumnContainsBlankValueThrowingException() throws Exception { formatter.format(new Document(new HashMap<String, Object>() {{ put("logtime", " "); }})); }
@Test public void testFormatWhenNoDateFormatSpecifiedRawColumnValueReturned() throws Exception { FileNameSuffixFormatter formatter = new FileNameSuffixFormatter("logtime", null); assertThat(formatter.format(new Document(new HashMap<String, Object>() {{ put("logtime", "Monday"); }})), is("Monday")); }
@Test public void testFormatWhenDateFormatIsSpecifiedAFormattedValueReturned() throws Exception { assertThat(formatter.format(new Document(new HashMap<String, Object>() {{ put("logtime", "2017-12-15T10:12:33.453Z"); }})), is("2017-12-15T10-12-33-453Z")); }