JavaTextMessageFormatFormatter extends AbstractMessageFormatter { @Override public String format(final String message, final Object[] arguments) { try { return new MessageFormat(message, locale).format(resolve(arguments)); } catch (IllegalArgumentException ex) { InternalLogger.log(Level.WARN, ex, "Illegal message format pattern '" + message + "'"); return message; } } JavaTextMessageFormatFormatter(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("{0}", 42)).isEqualTo("42"); }
@Test public void singlePlaceholder() { assertThat(format("Hello {0}!", "tinylog")).isEqualTo("Hello tinylog!"); }
@Test public void multiplePlaceholders() { assertThat(format("{2} = {0} + {1}", 1, 2, 3)).isEqualTo("3 = 1 + 2"); }
@Test public void lazyArgumentSupplier() { Supplier<Integer> supplier = () -> 42; assertThat(format("It is {0}", supplier)).isEqualTo("It is 42"); }
@Test public void choiceFormat() { assertThat(format("{0,choice,0#zero|1#one|1<multiple}", 0)).isEqualTo("zero"); assertThat(format("{0,choice,0#zero|1#one|1<multiple}", 1)).isEqualTo("one"); assertThat(format("{0,choice,0#zero|1#one|1<multiple}", 2)).isEqualTo("multiple"); }
@Test public void numberFormat() { assertThat(format(Locale.US, "{0,number,0.00}", 1)).isEqualTo("1.00"); assertThat(format(Locale.GERMANY, "{0,number,0.00}", 1)).isEqualTo("1,00"); }
@Test public void choiceAndNumberFormat() { assertThat(format("{0,choice,0#zero|1#one|1<{0,number,000}}", 0)).isEqualTo("zero"); assertThat(format("{0,choice,0#zero|1#one|1<{0,number,000}}", 42)).isEqualTo("042"); }
@Test public void tooManyArguments() { assertThat(format("Hello {0}!", "tinylog", "world")).isEqualTo("Hello tinylog!"); }
@Test public void tooFewArguments() { assertThat(format("Hello {0}!")).isEqualTo("Hello {0}!"); }
@Test public void ignoreEscapedPlaceholders() { assertThat(format("'{0}' {0}", "foo")).isEqualTo("{0} foo"); }
@Test public void illegalArgumentType() { assertThat(format("Test {0,number}!", "TEXT")).isEqualTo("Test {0,number}!"); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("WARN").containsOnlyOnce("Test {0,number}!"); }