### Question:
MessageBundle { public Map<String, String> getMessages() { return messages; } MessageBundle(LocaleSpec locale, String xml);  MessageBundle(LocaleSpec locale, Map<String, String> map);  MessageBundle(Element element);  MessageBundle(MessageBundle... bundles); private  MessageBundle(); String getLanguageDirection(); Map<String, String> getMessages(); String toJSONString(); @Override String toString(); static final MessageBundle EMPTY; }### Answer:
@Test public void normalMessageBundleParsesOk() throws Exception { MessageBundle bundle = new MessageBundle(locale, XML); assertEquals(MESSAGES, bundle.getMessages()); }
@Test public void duplicateKeyIgnored() throws Exception { String duplicateKeyXml = "<messagebundle>" + " <msg name='key'>value</msg>" + " <msg name='key'>value</msg>" + "</messagebundle>"; MessageBundle bundle = new MessageBundle(locale, duplicateKeyXml); assertEquals(ImmutableMap.of("key", "value"), bundle.getMessages()); }
@Test public void containsCdataSection() throws Exception { String cdataXml = "<messagebundle>" + " <msg name='key'><![CDATA[<span id='foo'>data</span>]]></msg>" + "</messagebundle>"; MessageBundle bundle = new MessageBundle(locale, cdataXml); assertEquals(ImmutableMap.of("key", "<span id='foo'>data</span>"), bundle.getMessages()); }
@Test public void extractFromElement() throws Exception { Element element = XmlUtil.parse(XML); MessageBundle bundle = new MessageBundle(element); assertEquals(MESSAGES, bundle.getMessages()); }
@Test public void extractNestedTagsVerbatim() throws Exception { String xml = "<messagebundle><msg name='key'>This is <x>nested</x> content</msg>" + "</messagebundle>"; Element element = XmlUtil.parse(xml); MessageBundle bundle = new MessageBundle(element); assertEquals("This is <x>nested</x> content", bundle.getMessages().get("key")); }