--- /dev/null
+package net.jaekl.cfb.analyze;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import net.jaekl.cfb.util.Command;
+import net.jaekl.cfb.xml.messages.BugCategory;
+import net.jaekl.cfb.xml.messages.BugPattern;
+import net.jaekl.cfb.xml.messages.MessageCollection;
+import net.jaekl.cfb.xml.messages.MessagesData;
+
+import org.junit.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class MessageMapTest {
+
+ private boolean containsCategory(MessageCollection msgColl, String catName) {
+ for (BugCategory cat : msgColl.getCategories()) {
+ if (catName.equals(cat.getCategory())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean containsPattern(MessageCollection msgColl, String patName) {
+ BugPattern pat = msgColl.getPattern(patName);
+ return(null != pat);
+ }
+
+ @Test
+ public void testParseMessagesData() throws FileNotFoundException, IOException, SAXException
+ {
+ MessageMap msgMap = new MessageMap();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(MessagesData.getData().getBytes(Command.UTF_8));
+ InputSource source = new InputSource(bais);
+ msgMap.parse(source);
+
+ MessageCollection msgColl = msgMap.getColl();
+ assertNotNull(msgColl);
+
+ // Non-exhaustive list of category names that should have been picked up by the parse
+ String[] expectedCategories = { "BAD_PRACTICE", "CORRECTNESS", "PERFORMANCE", "STYLE" };
+
+ for (String catName : expectedCategories) {
+ assertTrue(containsCategory(msgMap.getColl(), catName));
+ }
+
+ // Non-exhaustive list of pattern names that sohuld have been picked up by the parse
+ String[] expectedPatterns = { "DM_DEFAULT_ENCODING", "VO_VOLATILE_INCREMENT" };
+
+ for (String patName : expectedPatterns) {
+ assertTrue(containsPattern(msgMap.getColl(), patName));
+ }
+ }
+
+}