ThreadContextToken implements Token { @Override public void render(final LogEntry logEntry, final StringBuilder builder) { String value = logEntry.getContext().get(key); if (value == null) { builder.append(defaultValue); } else { builder.append(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 renderDefaultEmptyValue() { ThreadContextToken token = new ThreadContextToken("test"); assertThat(render(token, emptyMap())).isEmpty(); }
@Test public void renderDefinedEmptyValue() { ThreadContextToken token = new ThreadContextToken("test", "-"); assertThat(render(token, emptyMap())).isEqualTo("-"); }
@Test public void renderExistingProperty() { ThreadContextToken token = new ThreadContextToken("test"); assertThat(render(token, singletonMap("test", "42"))).isEqualTo("42"); }