UptimeToken implements Token { @Override public void apply(final LogEntry logEntry, final PreparedStatement statement, final int index) throws SQLException { long nanoseconds = logEntry.getTimestamp().calcDifferenceInNanoseconds(RuntimeProvider.getStartTime()); if (formatted) { StringBuilder builder = new StringBuilder(); format(builder, nanoseconds); statement.setString(index, builder.toString()); } else { statement.setLong(index, nanoseconds); } } UptimeToken();   UptimeToken(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 applyNanoseconds() throws SQLException { UptimeToken token = new UptimeToken(); Duration duration = Duration.ofNanos(42); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(duration), statement, 1); verify(statement).setLong(1, 42); }
@Test public void applyFormattedUptime() throws SQLException { UptimeToken token = new UptimeToken("H:mm"); Duration duration = Duration.ofHours(12).plusMinutes(30); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(duration), statement, 1); verify(statement).setString(1, "12:30"); }