KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cobertura > coveragedata > LineDataTest


1 /*
2  * Cobertura - http://cobertura.sourceforge.net/
3  *
4  * Copyright (C) 2005 Mark Doliner
5  *
6  * Cobertura is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License,
9  * or (at your option) any later version.
10  *
11  * Cobertura is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Cobertura; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  */

21
22 package net.sourceforge.cobertura.coveragedata;
23
24 import junit.framework.TestCase;
25
26 public class LineDataTest extends TestCase
27 {
28
29     private final LineData a = new LineData(10, "test1", "(I)B");
30     private final LineData b = new LineData(11, "test1", "(I)B");
31     private final LineData c = new LineData(12, "test2", "(I)B");
32     private final LineData d = new LineData(13, "test2", "(I)B");
33     private final LineData e = new LineData(14);
34     private final LineData f = new LineData(15);
35
36     public void testEquals()
37     {
38         assertFalse(a.equals(null));
39         assertFalse(a.equals(new Integer JavaDoc(4)));
40
41         assertTrue(a.equals(a));
42         assertFalse(a.equals(b));
43         assertFalse(a.equals(c));
44         assertFalse(a.equals(d));
45         assertFalse(a.equals(e));
46         assertFalse(a.equals(f));
47
48         LineData aPrime = new LineData(10, "test1", "(I)B");
49         assertTrue(a.equals(aPrime));
50     }
51
52     public void testHashCode()
53     {
54         assertEquals(a.hashCode(), a.hashCode());
55
56         LineData aPrime = new LineData(10, "test1", "(I)B");
57         assertEquals(a.hashCode(), aPrime.hashCode());
58     }
59
60     public void testGetLineNumber()
61     {
62         assertEquals(10, a.getLineNumber());
63         assertEquals(11, b.getLineNumber());
64         assertEquals(12, c.getLineNumber());
65         assertEquals(13, d.getLineNumber());
66         assertEquals(14, e.getLineNumber());
67         assertEquals(15, f.getLineNumber());
68     }
69
70     public void testGetNumbers()
71     {
72         assertEquals(1, a.getBranchCoverageRate(), 0);
73         assertEquals(0, a.getLineCoverageRate(), 0);
74         assertEquals(0, a.getNumberOfCoveredBranches());
75         assertEquals(0, a.getNumberOfCoveredLines());
76         assertEquals(0, a.getNumberOfValidBranches());
77         assertEquals(1, a.getNumberOfValidLines());
78
79         a.setBranch(true);
80         assertEquals(0, a.getBranchCoverageRate(), 0);
81         assertEquals(0, a.getLineCoverageRate(), 0);
82         assertEquals(0, a.getNumberOfCoveredBranches());
83         assertEquals(0, a.getNumberOfCoveredLines());
84         assertEquals(1, a.getNumberOfValidBranches());
85         assertEquals(1, a.getNumberOfValidLines());
86
87         for (int i = 0; i < 5; i++)
88         {
89             a.touch();
90             assertEquals(1, a.getBranchCoverageRate(), 0);
91             assertEquals(1, a.getLineCoverageRate(), 0);
92             assertEquals(1, a.getNumberOfCoveredBranches());
93             assertEquals(1, a.getNumberOfCoveredLines());
94             assertEquals(1, a.getNumberOfValidBranches());
95             assertEquals(1, a.getNumberOfValidLines());
96         }
97
98         a.setBranch(false);
99         assertEquals(1, a.getBranchCoverageRate(), 0);
100         assertEquals(1, a.getLineCoverageRate(), 0);
101         assertEquals(0, a.getNumberOfCoveredBranches());
102         assertEquals(1, a.getNumberOfCoveredLines());
103         assertEquals(0, a.getNumberOfValidBranches());
104         assertEquals(1, a.getNumberOfValidLines());
105     }
106
107     public void testSetConditional()
108     {
109         assertFalse(c.isBranch());
110         c.setBranch(true);
111         assertTrue(c.isBranch());
112         c.setBranch(false);
113         assertFalse(c.isBranch());
114     }
115
116     public void testSetMethodNameAndDescriptor()
117     {
118         e.setMethodNameAndDescriptor("test3", "(I)B");
119         assertEquals("test3", e.getMethodName());
120         assertEquals("(I)B", e.getMethodDescriptor());
121
122         f.setMethodNameAndDescriptor("test4", "(I)B");
123         assertEquals("test4", f.getMethodName());
124         assertEquals("(I)B", f.getMethodDescriptor());
125     }
126
127     public void testTouch()
128     {
129         assertEquals(0, a.getHits());
130         for (int i = 0; i < 400; i++)
131             a.touch();
132         assertEquals(400, a.getHits());
133     }
134
135 }
136
Popular Tags