UptimeToken implements Token { @Override public void render(final LogEntry logEntry, final StringBuilder builder) { long nanoseconds = logEntry.getTimestamp().calcDifferenceInNanoseconds(RuntimeProvider.getStartTime()); format(builder, nanoseconds); } UptimeToken();   UptimeToken(final String pattern); @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 renderDays() { UptimeToken token = new UptimeToken("d"); assertThat(render(token, Duration.ofDays(0))).isEqualTo("0"); assertThat(render(token, Duration.ofDays(1))).isEqualTo("1"); assertThat(render(token, Duration.ofDays(10))).isEqualTo("10"); assertThat(render(token, Duration.ofDays(100))).isEqualTo("100"); }
@Test public void renderHours() { UptimeToken token = new UptimeToken("H"); assertThat(render(token, Duration.ofHours(0))).isEqualTo("0"); assertThat(render(token, Duration.ofHours(1))).isEqualTo("1"); assertThat(render(token, Duration.ofHours(10))).isEqualTo("10"); assertThat(render(token, Duration.ofHours(100))).isEqualTo("100"); assertThat(render(token, Duration.ofHours(1000))).isEqualTo("1000"); }
@Test public void renderMinutes() { UptimeToken token = new UptimeToken("m"); assertThat(render(token, Duration.ofMinutes(0))).isEqualTo("0"); assertThat(render(token, Duration.ofMinutes(1))).isEqualTo("1"); assertThat(render(token, Duration.ofMinutes(10))).isEqualTo("10"); assertThat(render(token, Duration.ofMinutes(100))).isEqualTo("100"); assertThat(render(token, Duration.ofMinutes(1000))).isEqualTo("1000"); }
@Test public void renderSeconds() { UptimeToken token = new UptimeToken("s"); assertThat(render(token, Duration.ofSeconds(0))).isEqualTo("0"); assertThat(render(token, Duration.ofSeconds(1))).isEqualTo("1"); assertThat(render(token, Duration.ofSeconds(10))).isEqualTo("10"); assertThat(render(token, Duration.ofSeconds(100))).isEqualTo("100"); assertThat(render(token, Duration.ofSeconds(1000))).isEqualTo("1000"); }
@Test public void renderFractionOfSecond() { UptimeToken token = new UptimeToken("S"); assertThat(render(token, Duration.ofMillis(0))).isEqualTo("0"); assertThat(render(token, Duration.ofMillis(1))).isEqualTo("0"); assertThat(render(token, Duration.ofMillis(10))).isEqualTo("0"); assertThat(render(token, Duration.ofMillis(100))).isEqualTo("1"); assertThat(render(token, Duration.ofMillis(1000))).isEqualTo("10"); }
@Test public void renderAllPlaceholdersCombined() { UptimeToken token = new UptimeToken("d:HH:mm:ss.SSS"); Duration duration = Duration.ZERO; assertThat(render(token, duration)).isEqualTo("0:00:00:00.000"); duration = Duration.ofDays(1).plusHours(12).plusMinutes(30).plusSeconds(55); assertThat(render(token, duration)).isEqualTo("1:12:30:55.000"); duration = Duration.ofDays(90).plusHours(23).plusMinutes(59).plusSeconds(59).plusNanos(999_999_999); assertThat(render(token, duration)).isEqualTo("90:23:59:59.999"); }
@Test public void renderEscapedPhrase() { UptimeToken token = new UptimeToken("d 'days'"); Duration duration = Duration.ofDays(42); assertThat(render(token, duration)).isEqualTo("42 days"); }
@Test public void renderEscapedSingleQuote() { UptimeToken token = new UptimeToken("HH''mm"); Duration duration = Duration.ofHours(12); assertThat(render(token, duration)).isEqualTo("12'00"); }
@Test public void renderUnescapedSingleQuote() { UptimeToken token = new UptimeToken("HH'mm"); Duration duration = Duration.ofHours(12); assertThat(render(token, duration)).isEqualTo("12'00"); }