Formatter { protected String buildFullMessage(String message, Object... args) { StringBuilder stringBuilder = new StringBuilder(message.length()); int lastIndex = 0; int argIndex = 0; while (true) { int argPos = message.indexOf(ARGS_PATTERN, lastIndex); if (argPos == -1) { break; } stringBuilder.append(message.substring(lastIndex, argPos)); lastIndex = argPos + ARGS_PATTERN_LENGTH; if (argIndex < args.length) { stringBuilder.append(formatArgument(args[argIndex])); argIndex++; } } stringBuilder.append(message.substring(lastIndex)); return stringBuilder.toString(); }  abstract String buildLog(Level level, String loggerName, String message, Throwable thr, Object... args);  }
@Test public void testBuildFullMessageString() throws Exception { Assert.assertEquals("This is a test", formatter.buildFullMessage("{} is a test", "This")); Assert.assertEquals("This is a test", formatter.buildFullMessage("This is a {}", "test")); Assert.assertEquals("This is a test", formatter.buildFullMessage("This {} {} test", "is", "a")); Assert.assertEquals("This is a test", formatter.buildFullMessage("This {} a test", "is", "a")); }
@Test public void testBuildFullMessageIntArray() throws Exception { Integer[] values = new Integer[] { 1, 2 }; Assert.assertEquals("Values = [1, 2]", formatter.buildFullMessage("Values = {}", new Object[] { values })); }
@Test public void testBuildFullMessageObjectArray() throws Exception { SomeObject[] values = new SomeObject[] { new SomeObject("a"), new SomeObject("b") }; Assert.assertEquals("Objects = [a, b]", formatter.buildFullMessage("Objects = {}", new Object[] { values })); }
@Test public void testBuildFullMessageList() throws Exception { List<SomeObject> values = Arrays.asList(new SomeObject("a"), new SomeObject("b")); Assert.assertEquals("Objects = [a, b]", formatter.buildFullMessage("Objects = {}", values)); }