PrintfStyleFormatter extends AbstractMessageFormatter { @Override public String format(final String message, final Object[] arguments) { try { return String.format(locale, message, resolve(arguments)); } catch (IllegalFormatException ex) { InternalLogger.log(Level.WARN, ex, "Illegal printf format message '" + message + "'"); return message; } } PrintfStyleFormatter(final Locale locale); @Override String format(final String message, final Object[] arguments);  }
@Test public void withoutPlaceholders() { assertThat(format("Hello World!")).isEqualTo("Hello World!"); }
@Test public void onlyPlaceholder() { assertThat(format("%d", 42)).isEqualTo("42"); }
@Test public void singlePlaceholder() { assertThat(format("Hello %s!", "tinylog")).isEqualTo("Hello tinylog!"); }
@Test public void multiplePlaceholders() { assertThat(format("%d + %d = %d", 1, 2, 3)).isEqualTo("1 + 2 = 3"); }
@Test public void lazyArgumentSupplier() { Supplier<Integer> supplier = () -> 42; assertThat(format("It is %d", supplier)).isEqualTo("It is 42"); }
@Test public void tooManyArguments() { assertThat(format("Hello %s!", "tinylog", "world")).isEqualTo("Hello tinylog!"); }
@Test public void tooFewArguments() { assertThat(format("Hello %s!")).isEqualTo("Hello %s!"); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("WARN").containsOnlyOnce("Hello %s!"); }
@Test public void invalidFormatSpecifier() { assertThat(format("Hello %!", "tinylog")).isEqualTo("Hello %!"); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("WARN").containsOnlyOnce("Hello %!"); }