KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > metrics > TestMetricsConfiguration


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.metrics;
34
35 import junit.framework.*;
36
37 import java.util.*;
38
39 public class TestMetricsConfiguration extends TestCase {
40     private MetricsConfiguration config;
41     private MeasurementDescriptor d1;
42     private MeasurementDescriptor d2;
43     
44     protected void setUp() {
45         config = new MetricsConfiguration();
46
47         d1 = new MeasurementDescriptor();
48         d2 = new MeasurementDescriptor();
49     }
50     
51     public void testCreate() {
52         assertNotNull("ProjectMeasurements is null", config.getProjectMeasurements());
53         assertTrue("ProjectMeasurements is not emty", config.getProjectMeasurements().isEmpty());
54         assertNotNull("GroupMeasurements is null", config.getGroupMeasurements());
55         assertTrue("GroupMeasurements is not emty", config.getGroupMeasurements().isEmpty());
56         assertNotNull("ClassMeasurements is null", config.getClassMeasurements());
57         assertTrue("ClassMeasurements is not emty", config.getClassMeasurements().isEmpty());
58         assertNotNull("MethodMeasurements is null", config.getMethodMeasurements());
59         assertTrue("MethodMeasurements is not emty", config.getMethodMeasurements().isEmpty());
60     }
61
62     public void testAddProjectMeasurement() {
63         assertEquals(0, config.getProjectMeasurements().size());
64
65         config.addProjectMeasurement(d1);
66         assertEquals(1, config.getProjectMeasurements().size());
67         assertTrue(config.getProjectMeasurements().contains(d1));
68
69         config.addProjectMeasurement(d2);
70         assertEquals(2, config.getProjectMeasurements().size());
71         assertTrue(config.getProjectMeasurements().contains(d2));
72
73         assertEquals(d1, config.getProjectMeasurements().get(0));
74         assertEquals(d2, config.getProjectMeasurements().get(1));
75     }
76
77     public void testAddGroupMeasurement() {
78         assertEquals(0, config.getGroupMeasurements().size());
79
80         config.addGroupMeasurement(d1);
81         assertEquals(1, config.getGroupMeasurements().size());
82         assertTrue(config.getGroupMeasurements().contains(d1));
83
84         config.addGroupMeasurement(d2);
85         assertEquals(2, config.getGroupMeasurements().size());
86         assertTrue(config.getGroupMeasurements().contains(d2));
87
88         assertEquals(d1, config.getGroupMeasurements().get(0));
89         assertEquals(d2, config.getGroupMeasurements().get(1));
90     }
91
92     public void testAddClassMeasurement() {
93         assertEquals(0, config.getClassMeasurements().size());
94
95         config.addClassMeasurement(d1);
96         assertEquals(1, config.getClassMeasurements().size());
97         assertTrue(config.getClassMeasurements().contains(d1));
98
99         config.addClassMeasurement(d2);
100         assertEquals(2, config.getClassMeasurements().size());
101         assertTrue(config.getClassMeasurements().contains(d2));
102
103         assertEquals(d1, config.getClassMeasurements().get(0));
104         assertEquals(d2, config.getClassMeasurements().get(1));
105     }
106
107     public void testAddMethodMeasurement() {
108         assertEquals(0, config.getMethodMeasurements().size());
109
110         config.addMethodMeasurement(d1);
111         assertEquals(1, config.getMethodMeasurements().size());
112         assertTrue(config.getMethodMeasurements().contains(d1));
113
114         config.addMethodMeasurement(d2);
115         assertEquals(2, config.getMethodMeasurements().size());
116         assertTrue(config.getMethodMeasurements().contains(d2));
117
118         assertEquals(d1, config.getMethodMeasurements().get(0));
119         assertEquals(d2, config.getMethodMeasurements().get(1));
120     }
121
122     public void testGroupDefinitions() {
123         Collection groups;
124
125         groups = config.getGroups("foobar");
126         assertEquals(0, groups.size());
127         
128         config.addGroupDefinition("foo", "/foo/");
129         groups = config.getGroups("foobar");
130         assertEquals(1, groups.size());
131         assertTrue(groups.contains("foo"));
132
133         config.addGroupDefinition("bar", "/bar/");
134         groups = config.getGroups("foobar");
135         assertEquals(2, groups.size());
136         assertTrue(groups.contains("foo"));
137         assertTrue(groups.contains("bar"));
138
139         config.addGroupDefinition("baz", "/baz/");
140         groups = config.getGroups("foobar");
141         assertEquals(2, groups.size());
142         assertTrue(groups.contains("foo"));
143         assertTrue(groups.contains("bar"));
144     }
145
146     public void testGroupDefinitionsWithMultipleREs() {
147         Collection groups;
148
149         groups = config.getGroups("foobar");
150         assertEquals(0, groups.size());
151         
152         config.addGroupDefinition("foo", "/foo/");
153         config.addGroupDefinition("foo", "/bar/");
154
155         groups = config.getGroups("foo only");
156         assertEquals(1, groups.size());
157         assertTrue(groups.contains("foo"));
158
159         groups = config.getGroups("bar only");
160         assertEquals(1, groups.size());
161         assertTrue(groups.contains("foo"));
162     }
163 }
164
Popular Tags