LogMessageIdFormat { String formatMessage(Object[] args) { StringBuilder sb = new StringBuilder(); int argsLength = args == null ? 0 : args.length; int size = tokens.size(); int argsUse = 0; for (int i = 0; i < size; i++) { Object f = tokens.get(i); if (f == PLACEHOLDER) { Object argument = argsUse < argsLength ? args[argsUse] : ""; sb.append(argument); argsUse++; } else { sb.append(f); } } return sb.toString(); } LogMessageIdFormat(String message);   }
@Test public void testFormats() { Assert.assertEquals("", new LogMessageIdFormat("").formatMessage(new Integer[]{1,2,3})); Assert.assertEquals("abcd", new LogMessageIdFormat("abcd").formatMessage(null)); Assert.assertEquals("1a2b3", new LogMessageIdFormat("1{}2{}3").formatMessage(new String[]{"a", "b"})); Assert.assertEquals("123", new LogMessageIdFormat("{}{}{}").formatMessage(new Integer[]{1,2,3})); Assert.assertEquals("A1a2b3B", new LogMessageIdFormat("{}1{}2{}3{}").formatMessage(new String[]{"A", "a", "b", "B"})); Assert.assertEquals("A123", new LogMessageIdFormat("{}1{}2{}3{}").formatMessage(new String[]{"A"})); Assert.assertEquals("", new LogMessageIdFormat("{}{}{}").formatMessage(new Integer[]{})); Assert.assertEquals("", new LogMessageIdFormat("{}{}{}").formatMessage(null)); }