Display LocalVariables along with Locations in the html report.
[cfb.git] / test / net / jaekl / cfb / analyze / MessageMapTest.java
1 package net.jaekl.cfb.analyze;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5
6 import java.io.ByteArrayInputStream;
7 import java.io.FileNotFoundException;
8 import java.io.IOException;
9
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;
15
16 import org.junit.Test;
17 import org.xml.sax.InputSource;
18 import org.xml.sax.SAXException;
19
20 public class MessageMapTest {
21
22         private boolean containsCategory(MessageCollection msgColl, String catName) {
23                 for (BugCategory cat : msgColl.getCategories()) {
24                         if (catName.equals(cat.getCategory())) {
25                                 return true;
26                         }
27                 }
28                 return false;
29         }
30         
31         private boolean containsPattern(MessageCollection msgColl, String patName) {
32                 BugPattern pat = msgColl.getPattern(patName);
33                 return(null != pat);
34         }
35         
36         @Test
37         public void testParseMessagesData() throws FileNotFoundException, IOException, SAXException 
38         {
39                 MessageMap msgMap = new MessageMap();
40                 
41                 ByteArrayInputStream bais = new ByteArrayInputStream(MessagesData.getData().getBytes(Command.UTF_8));
42                 InputSource source = new InputSource(bais);             
43                 msgMap.parse(source);
44                 
45                 MessageCollection msgColl = msgMap.getColl();
46                 assertNotNull(msgColl);
47                 
48                 // Non-exhaustive list of category names that should have been picked up by the parse
49                 String[] expectedCategories = { "BAD_PRACTICE", "CORRECTNESS", "PERFORMANCE", "STYLE" };
50         
51                 for (String catName : expectedCategories) {
52                         assertTrue(containsCategory(msgMap.getColl(), catName));
53                 }
54                 
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" };
57                 
58                 for (String patName : expectedPatterns) {
59                         assertTrue(containsPattern(msgMap.getColl(), patName));
60                 }
61         }
62
63 }