MessageServiceImpl implements MessageService { protected void mergeMessages(Collection<Message> messages, Collection<Message> messagesToMerge) { for (Message message : messagesToMerge) { if (!messages.contains(message)) { messages.add(message); } } }  Message getMessage(String namespace, String component, String key); Message getMessage(String namespace, String component, String key, String locale); String getMessageText(String namespace, String component, String key); String getMessageText(String namespace, String component, String key, String locale); String getMessageText(String key); String getMessageText(String key, String locale); Collection<Message> getAllMessagesForComponent(String namespace, String component); Collection<Message> getAllMessagesForComponent(String namespace, String component, String locale); void setMessageProviders(List<MessageProvider> messageProviders);  }
@Test public void testMergeMessages() { Collection<Message> messages1 = new ArrayList<Message>(); Collection<Message> messages2 = new ArrayList<Message>(); MessageBuilder builder = MessageBuilder.create("Default", "All", "Test Message"); Message message1 = builder.build(); builder.setKey("Test Message 2"); Message message2 = builder.build(); builder.setComponentCode("TestView"); Message message3 = builder.build(); builder.setNamespaceCode("KR-SAP"); Message message4 = builder.build(); Message message5 = builder.build(); messages1.add(message1); messages1.add(message2); messages1.add(message4); messages2.add(message1); messages2.add(message3); messages2.add(message4); messages2.add(message5); MessageServiceImpl messageServiceImpl = new MessageServiceImpl(); messageServiceImpl.mergeMessages(messages1, messages2); assertEquals("Merged map is not correct size", 5, messages1.size()); }