DateToken implements Token { @Override public void render(final LogEntry logEntry, final StringBuilder builder) { builder.append(formatter.format(logEntry.getTimestamp())); } DateToken();   DateToken(final String pattern); @Override Collection<LogEntryValue> getRequiredLogEntryValues(); @Override void render(final LogEntry logEntry, final StringBuilder builder); @Override void apply(final LogEntry logEntry, final PreparedStatement statement, final int index);  }
@Test public void renderDatePattern() { DateToken token = new DateToken("yyyy-MM-dd"); assertThat(render(token, LocalDateTime.of(2016, 1, 1, 0, 0))).isEqualTo("2016-01-01"); assertThat(render(token, LocalDateTime.of(2016, 1, 1, 12, 0))).isEqualTo("2016-01-01"); assertThat(render(token, LocalDateTime.of(2016, 1, 2, 0, 0))).isEqualTo("2016-01-02"); }
@Test public void renderTimePattern() { DateToken token = new DateToken("HH:mm:ss.SSS"); assertThat(render(token, LocalDateTime.of(2016, 1, 1, 0, 0, 0))).isEqualTo("00:00:00.000"); assertThat(render(token, LocalDateTime.of(2016, 1, 1, 2, 3, 4))).isEqualTo("02:03:04.000"); assertThat(render(token, LocalDateTime.of(2016, 1, 2, 0, 0, 0))).isEqualTo("00:00:00.000"); }
@Test public void renderDefaultPattern() { DateToken token = new DateToken(); assertThat(render(token, LocalDateTime.of(2016, 6, 30, 12, 0))).containsSubsequence("2016", "06", "30", "12", "00"); assertThat(render(token, LocalDateTime.of(2016, 6, 30, 12, 15))).containsSubsequence("2016", "06", "30", "12", "15"); }