Display LocalVariables along with Locations in the html report.
[cfb.git] / test / net / jaekl / cfb / analyze / MessageMapTest.java
diff --git a/test/net/jaekl/cfb/analyze/MessageMapTest.java b/test/net/jaekl/cfb/analyze/MessageMapTest.java
new file mode 100644 (file)
index 0000000..45ada91
--- /dev/null
@@ -0,0 +1,63 @@
+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));
+               }
+       }
+
+}