LineNumberToken implements Token { @Override public void apply(final LogEntry logEntry, final PreparedStatement statement, final int index) throws SQLException { int line = logEntry.getLineNumber(); if (line >= 0) { statement.setInt(index, line); } else { statement.setNull(index, Types.INTEGER); } } LineNumberToken(); @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 applyValidLineNumber() throws SQLException { LineNumberToken token = new LineNumberToken(); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(42), statement, 1); verify(statement).setInt(1, 42); }
@Test public void applyInvalidLineNumber() throws SQLException { LineNumberToken token = new LineNumberToken(); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(-1), statement, 1); verify(statement).setNull(1, Types.INTEGER); }