ThreadContextToken implements Token { @Override public void apply(final LogEntry logEntry, final PreparedStatement statement, final int index) throws SQLException { String value = logEntry.getContext().get(key); if (value == null && defaultValue != DEFAULT_EMPTY_VALUE) { statement.setString(index, defaultValue); } else { statement.setString(index, value); } } ThreadContextToken(final String key);   ThreadContextToken(final String key, final String defaultValue); @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 applyDefaultEmptyTag() throws SQLException { ThreadContextToken token = new ThreadContextToken("test"); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(emptyMap()), statement, 1); verify(statement).setString(1, null); }
@Test public void applyDefinedEmptyValue() throws SQLException { ThreadContextToken token = new ThreadContextToken("test", "-"); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(emptyMap()), statement, 1); verify(statement).setString(1, "-"); }
@Test public void applyExistingProperty() throws SQLException { ThreadContextToken token = new ThreadContextToken("test"); PreparedStatement statement = mock(PreparedStatement.class); token.apply(createLogEntry(singletonMap("test", "42")), statement, 1); verify(statement).setString(1, "42"); }