ExtendedMessageFormatter { public static List<String> parseMessage(final String messagePattern, Object[] arguments) { if (messagePattern == null) { return null; } if (arguments == null || arguments.length == 0) { return Arrays.asList(messagePattern); } List<String> messageList = new ArrayList<>(arguments.length + 1); MessageParser parser = new MessageParser(messagePattern, false); StringBuilder lastElement = new StringBuilder(); for (MessageElement element = parser.next(), previous = null; element != null; previous = element, element = parser.next()) { if (arguments.length < messageList.size()) { lastElement.append(element.getString()); } else { if (element instanceof MessageString) { messageList.add(element.getString()); } else if (!(previous instanceof MessageString)) { messageList.add(""); } } } if (lastElement.length() > 0 || parser.getCurrentMessageElement() instanceof MessageIndex) { messageList.add(lastElement.toString()); } return messageList; } private  ExtendedMessageFormatter(); static List<String> parseMessage(final String messagePattern, Object[] arguments);  }
@Test void nullMessage() { assertNull(ExtendedMessageFormatter.parseMessage(null, new Object[]{})); }
@Test void emptyMessage() { assertEquals(Arrays.asList(""), ExtendedMessageFormatter.parseMessage("", new Object[]{})); }
@Test void nNullArguments() { assertEquals(Arrays.asList("message"), ExtendedMessageFormatter.parseMessage("message", null)); }
@Test void emptyArguments() { assertEquals(Arrays.asList("message"), ExtendedMessageFormatter.parseMessage("message", new Object[]{})); }
@Test void plain() { assertEquals(Arrays.asList("message"), ExtendedMessageFormatter.parseMessage("message", new Object[]{ "0" })); }
@Test void withArguments() { assertEquals(Arrays.asList("hello ", " world"), ExtendedMessageFormatter.parseMessage("hello {} world", new Object[]{ "0" })); }
@Test void withoutArguments() { assertEquals(Arrays.asList("hello {} world"), ExtendedMessageFormatter.parseMessage("hello {} world", new Object[]{})); }
@Test void withEndingArgument() { assertEquals(Arrays.asList("hello ", ""), ExtendedMessageFormatter.parseMessage("hello {}", new Object[]{ "0" })); }
@Test void withoutTooMuchArguments() { assertEquals(Arrays.asList("hello ", " world"), ExtendedMessageFormatter.parseMessage("hello {} world", new Object[]{ "0", "1" })); }
@Test void withOnlyArguments() { assertEquals(Arrays.asList("", "", ""), ExtendedMessageFormatter.parseMessage("{}{}", new Object[]{ "0", "1" })); }