CodeFormatter { String format(char expressionStart, Object content, String indent, CodeWriter writer, Object... args) { String expression = String.valueOf(content); if (args.length == 0 && expression.indexOf(expressionStart) == -1) { return expression; } return parse(expressionStart, new State(content, indent, writer, args)); }    }
@Test public void formatsDollarLiterals() { CodeFormatter formatter = new CodeFormatter(); String result = formatter.format('$', "hello $$", "", createWriter()); assertThat(result, equalTo("hello $")); }
@Test public void requiresTextAfterOpeningBrace() { Assertions.assertThrows(IllegalArgumentException.class, () -> { CodeFormatter formatter = new CodeFormatter(); formatter.format('$', "hello ${", "", createWriter(), "there"); }); }
@Test public void ensuresFormatterIsValid() { Assertions.assertThrows(IllegalArgumentException.class, () -> { CodeFormatter formatter = new CodeFormatter(); formatter.format('$', "$L", "", createWriter(), "hi"); }); }