MessageUtil { public static String formatMessage(String message, Object...params) { if (message == null || params == null || params.length == 0) { return message; } return MessageFormat.format(message, params); }  static String getMessage(ResourceBundle bundle, String key, Object...params); static String formatMessage(String message, Object...params);  }
@Test public void formatMessage() { assertNull(MessageUtil.formatMessage(null, (Object[]) null)); String message = "message {0}, {1}, {2}, {3}, {4}"; assertSame(message, MessageUtil.formatMessage(message, (Object[]) null)); assertSame(message, MessageUtil.formatMessage(message, new Object[0])); assertEquals("message aa, {1}, {2}, {3}, {4}", MessageUtil.formatMessage(message, "aa")); assertEquals("message aa, bb, {2}, {3}, {4}", MessageUtil.formatMessage(message, "aa", "bb")); assertEquals("message aa, bb, cc, {3}, {4}", MessageUtil.formatMessage(message, "aa", "bb", "cc")); assertEquals("message aa, bb, cc, dd, {4}", MessageUtil.formatMessage(message, "aa", "bb", "cc", "dd")); assertEquals("message aa, bb, cc, dd, ee", MessageUtil.formatMessage(message, "aa", "bb", "cc", "dd", "ee")); }