1 package net.jaekl.cfb.analyze;
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
6 import java.io.ByteArrayInputStream;
7 import java.io.FileNotFoundException;
8 import java.io.IOException;
10 import net.jaekl.cfb.util.Command;
11 import net.jaekl.cfb.xml.messages.BugCategory;
12 import net.jaekl.cfb.xml.messages.BugPattern;
13 import net.jaekl.cfb.xml.messages.MessageCollection;
14 import net.jaekl.cfb.xml.messages.MessagesData;
16 import org.junit.Test;
17 import org.xml.sax.InputSource;
18 import org.xml.sax.SAXException;
20 public class MessageMapTest {
22 private boolean containsCategory(MessageCollection msgColl, String catName) {
23 for (BugCategory cat : msgColl.getCategories()) {
24 if (catName.equals(cat.getCategory())) {
31 private boolean containsPattern(MessageCollection msgColl, String patName) {
32 BugPattern pat = msgColl.getPattern(patName);
37 public void testParseMessagesData() throws FileNotFoundException, IOException, SAXException
39 MessageMap msgMap = new MessageMap();
41 ByteArrayInputStream bais = new ByteArrayInputStream(MessagesData.getData().getBytes(Command.UTF_8));
42 InputSource source = new InputSource(bais);
45 MessageCollection msgColl = msgMap.getColl();
46 assertNotNull(msgColl);
48 // Non-exhaustive list of category names that should have been picked up by the parse
49 String[] expectedCategories = { "BAD_PRACTICE", "CORRECTNESS", "PERFORMANCE", "STYLE" };
51 for (String catName : expectedCategories) {
52 assertTrue(containsCategory(msgMap.getColl(), catName));
55 // Non-exhaustive list of pattern names that sohuld have been picked up by the parse
56 String[] expectedPatterns = { "DM_DEFAULT_ENCODING", "VO_VOLATILE_INCREMENT" };
58 for (String patName : expectedPatterns) {
59 assertTrue(containsPattern(msgMap.getColl(), patName));