IndentationToken implements Token { @Override public void render(final LogEntry logEntry, final StringBuilder builder) { StringBuilder source = new StringBuilder(INITIAL_CAPACITY); token.render(logEntry, source); int head = 0; for (int i = source.indexOf(NEW_LINE, head); i != -1; i = source.indexOf(NEW_LINE, head)) { builder.append(source, head, i + NEW_LINE.length()); head = i + NEW_LINE.length(); if (head < source.length()) { builder.append(spaces); while (head < source.length() && source.charAt(head) == '\t') { builder.append(spaces); ++head; } } } builder.append(source, head, source.length()); } IndentationToken(final Token token, final int indentation); @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 renderSingleLine() { IndentationToken token = new IndentationToken(new PlainTextToken("Hello World!"), 2); assertThat(render(token)).isEqualTo("Hello World!"); }
@Test public void renderTwoLines() { IndentationToken token = new IndentationToken(new PlainTextToken("Hello" + NEW_LINE + "World!"), 2); assertThat(render(token)).isEqualTo("Hello" + NEW_LINE + " World!"); }
@Test public void renderMultipleLines() { IndentationToken token = new IndentationToken(new PlainTextToken("A" + NEW_LINE + "B" + NEW_LINE + "C"), 2); assertThat(render(token)).isEqualTo("A" + NEW_LINE + " B" + NEW_LINE + " C"); }
@Test public void renderTabulators() { IndentationToken token = new IndentationToken(new PlainTextToken("Hello" + NEW_LINE + "\tWorld\t!"), 2); assertThat(render(token)).isEqualTo("Hello" + NEW_LINE + " World\t!"); }