LegacyMessageFormatter extends AbstractMessageFormatter { @Override public String format(final String message, final Object[] arguments) { int length = message.length(); StringBuilder builder = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); int argumentIndex = 0; for (int index = 0; index < length; ++index) { char character = message.charAt(index); if (character == '{' && index + 1 < length && message.charAt(index + 1) == '}' && argumentIndex < arguments.length) { builder.append(resolve(arguments[argumentIndex++])); index += 1; } else { builder.append(character); } } return builder.toString(); } LegacyMessageFormatter(); @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("{}", 42)).isEqualTo("42"); }
@Test public void singlePlaceholder() { assertThat(format("Hello {}!", "tinylog")).isEqualTo("Hello tinylog!"); }
@Test public void multiplePlaceholders() { assertThat(format("{} + {} = {}", 1, 2, 3)).isEqualTo("1 + 2 = 3"); }
@Test public void lazyArgumentSupplier() { Supplier<Integer> supplier = () -> 42; assertThat(format("It is {}", supplier)).isEqualTo("It is 42"); }
@Test public void tooManyArguments() { assertThat(format("Hello {}!", "tinylog", "world")).isEqualTo("Hello tinylog!"); }
@Test public void tooFewArguments() { assertThat(format("Hello {}!")).isEqualTo("Hello {}!"); }
@Test public void missingOpeningCurlyBracket() { assertThat(format("} Hello", "tinylog")).isEqualTo("} Hello"); assertThat(format("Hello }", "tinylog")).isEqualTo("Hello }"); }
@Test public void missingClosingCurlyBracket() { assertThat(format("{ Hello", "tinylog")).isEqualTo("{ Hello"); assertThat(format("Hello {", "tinylog")).isEqualTo("Hello {"); }
@Test public void ignorePlaceholdersWithText() { assertThat(format("{foo} {}", "bar")).isEqualTo("{foo} bar"); }