MinimumSizeToken implements Token { @Override public void apply(final LogEntry logEntry, final PreparedStatement statement, final int index) throws SQLException { StringBuilder builder = new StringBuilder(); render(logEntry, builder); statement.setString(index, builder.toString()); } MinimumSizeToken(final Token token, final int size); @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 applyLongerTextThanMinimumSize() throws SQLException { MinimumSizeToken token = new MinimumSizeToken(new PlainTextToken("Hello!"), 5); PreparedStatement statement = mock(PreparedStatement.class); token.apply(LogEntryBuilder.empty().create(), statement, 1); verify(statement).setString(1, "Hello!"); }
@Test public void applyTextOfEqualLengthToMinimumSize() throws SQLException { MinimumSizeToken token = new MinimumSizeToken(new PlainTextToken("Hello!"), 6); PreparedStatement statement = mock(PreparedStatement.class); token.apply(LogEntryBuilder.empty().create(), statement, 1); verify(statement).setString(1, "Hello!"); }
@Test public void applyShorterTextThanMinimumSize() throws SQLException { PlainTextToken token = new PlainTextToken("Hello!"); LogEntry logEntry = LogEntryBuilder.empty().create(); PreparedStatement statement = mock(PreparedStatement.class); new MinimumSizeToken(token, 7).apply(logEntry, statement, 1); verify(statement).setString(1, "Hello! "); statement = mock(PreparedStatement.class); new MinimumSizeToken(token, 8).apply(logEntry, statement, 1); verify(statement).setString(1, "Hello! "); }