DateToken implements Token { @Override public void apply(final LogEntry logEntry, final PreparedStatement statement, final int index) throws SQLException { if (formatted) { statement.setString(index, formatter.format(logEntry.getTimestamp())); } else { statement.setTimestamp(index, logEntry.getTimestamp().toSqlTimestamp()); } } 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 applyTimestamp() throws SQLException { DateToken token = new DateToken(); LocalDateTime now = LocalDateTime.now(); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(now), statement, 1); verify(statement).setTimestamp(1, Timestamp.valueOf(now)); }
@Test public void applyString() throws SQLException { DateToken token = new DateToken("yyyy-MM-dd HH:mm"); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(LocalDateTime.of(2016, 6, 30, 12, 15)), statement, 1); verify(statement).setString(1, "2016-06-30 12:15"); }