Add unit tests. Make DbStore handle cases where the bug type or category
[cfb.git] / test / net / jaekl / cfb / xml / BugInstanceTest.java
1 package net.jaekl.cfb.xml;
2
3 import static org.junit.Assert.*;
4
5 import net.jaekl.cfb.store.Location;
6
7 import org.junit.Test;
8
9 public class BugInstanceTest {
10
11         @Test
12         public void testGetPrincipalLocation() {
13                 Location[][][] data = 
14                 {
15                         {
16                                 // Location(Long id, String className, String methodName, String methodRole, Integer startLine, Integer endLine)
17                                 { 
18                                         // input
19                                         new Location( 1L, "ClassOne", "methodOne", "METHOD_CALLED", 1, 12),
20                                         new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34)
21                                 },
22                                 {
23                                         // expected result
24                                         new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34)                                          
25                                 }
26                         },
27                         {
28                                 {
29                                         // input:  empty set
30                                 },
31                                 {
32                                         // expected result
33                                         null
34                                 }
35                         },
36                         {
37                                 {
38                                         // input
39                                         new Location( 3L, "ClassThree", "methodThree", null, 34, 45),
40                                         new Location( 4L, "ClassFour",  "methodFour",  null, 45, 56),
41                                         new Location( 5L, "ClassFive",  "methodFive",  null, 56, 67)
42                                 },
43                                 {
44                                         // expected result
45                                         new Location( 3L, "ClassThree", "methodThree", null, 34, 45),
46                                 }
47                         },
48                         {
49                                 {
50                                         // input
51                                         new Location( 6L, "CLassSix",   "methodSix",   "METHOD_CALLED", 67, 78)
52                                 },
53                                 {
54                                         // expected result
55                                         null
56                                 }
57                         }
58                 };
59                 
60                 for (Location[][] datum : data) {
61                         Location[] input = datum[0];
62                         Location expected = datum[1][0];
63                         
64                         BugInstance bug = new BugInstance(
65                                                 101L, // id
66                                                 "CATEGORY",
67                                                 "TYPE",
68                                                 input,
69                                                 new LocalVariable[0]
70                                         );
71                         Location actual = bug.getPrincipalLocation();
72                         
73                         assertEquals(expected, actual);
74                 }
75         }
76
77 }