001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.metrics;
034:
035: import junit.framework.*;
036:
037: import java.util.*;
038:
039: public class TestMetricsConfiguration extends TestCase {
040: private MetricsConfiguration config;
041: private MeasurementDescriptor d1;
042: private MeasurementDescriptor d2;
043:
044: protected void setUp() {
045: config = new MetricsConfiguration();
046:
047: d1 = new MeasurementDescriptor();
048: d2 = new MeasurementDescriptor();
049: }
050:
051: public void testCreate() {
052: assertNotNull("ProjectMeasurements is null", config
053: .getProjectMeasurements());
054: assertTrue("ProjectMeasurements is not emty", config
055: .getProjectMeasurements().isEmpty());
056: assertNotNull("GroupMeasurements is null", config
057: .getGroupMeasurements());
058: assertTrue("GroupMeasurements is not emty", config
059: .getGroupMeasurements().isEmpty());
060: assertNotNull("ClassMeasurements is null", config
061: .getClassMeasurements());
062: assertTrue("ClassMeasurements is not emty", config
063: .getClassMeasurements().isEmpty());
064: assertNotNull("MethodMeasurements is null", config
065: .getMethodMeasurements());
066: assertTrue("MethodMeasurements is not emty", config
067: .getMethodMeasurements().isEmpty());
068: }
069:
070: public void testAddProjectMeasurement() {
071: assertEquals(0, config.getProjectMeasurements().size());
072:
073: config.addProjectMeasurement(d1);
074: assertEquals(1, config.getProjectMeasurements().size());
075: assertTrue(config.getProjectMeasurements().contains(d1));
076:
077: config.addProjectMeasurement(d2);
078: assertEquals(2, config.getProjectMeasurements().size());
079: assertTrue(config.getProjectMeasurements().contains(d2));
080:
081: assertEquals(d1, config.getProjectMeasurements().get(0));
082: assertEquals(d2, config.getProjectMeasurements().get(1));
083: }
084:
085: public void testAddGroupMeasurement() {
086: assertEquals(0, config.getGroupMeasurements().size());
087:
088: config.addGroupMeasurement(d1);
089: assertEquals(1, config.getGroupMeasurements().size());
090: assertTrue(config.getGroupMeasurements().contains(d1));
091:
092: config.addGroupMeasurement(d2);
093: assertEquals(2, config.getGroupMeasurements().size());
094: assertTrue(config.getGroupMeasurements().contains(d2));
095:
096: assertEquals(d1, config.getGroupMeasurements().get(0));
097: assertEquals(d2, config.getGroupMeasurements().get(1));
098: }
099:
100: public void testAddClassMeasurement() {
101: assertEquals(0, config.getClassMeasurements().size());
102:
103: config.addClassMeasurement(d1);
104: assertEquals(1, config.getClassMeasurements().size());
105: assertTrue(config.getClassMeasurements().contains(d1));
106:
107: config.addClassMeasurement(d2);
108: assertEquals(2, config.getClassMeasurements().size());
109: assertTrue(config.getClassMeasurements().contains(d2));
110:
111: assertEquals(d1, config.getClassMeasurements().get(0));
112: assertEquals(d2, config.getClassMeasurements().get(1));
113: }
114:
115: public void testAddMethodMeasurement() {
116: assertEquals(0, config.getMethodMeasurements().size());
117:
118: config.addMethodMeasurement(d1);
119: assertEquals(1, config.getMethodMeasurements().size());
120: assertTrue(config.getMethodMeasurements().contains(d1));
121:
122: config.addMethodMeasurement(d2);
123: assertEquals(2, config.getMethodMeasurements().size());
124: assertTrue(config.getMethodMeasurements().contains(d2));
125:
126: assertEquals(d1, config.getMethodMeasurements().get(0));
127: assertEquals(d2, config.getMethodMeasurements().get(1));
128: }
129:
130: public void testGroupDefinitions() {
131: Collection groups;
132:
133: groups = config.getGroups("foobar");
134: assertEquals(0, groups.size());
135:
136: config.addGroupDefinition("foo", "/foo/");
137: groups = config.getGroups("foobar");
138: assertEquals(1, groups.size());
139: assertTrue(groups.contains("foo"));
140:
141: config.addGroupDefinition("bar", "/bar/");
142: groups = config.getGroups("foobar");
143: assertEquals(2, groups.size());
144: assertTrue(groups.contains("foo"));
145: assertTrue(groups.contains("bar"));
146:
147: config.addGroupDefinition("baz", "/baz/");
148: groups = config.getGroups("foobar");
149: assertEquals(2, groups.size());
150: assertTrue(groups.contains("foo"));
151: assertTrue(groups.contains("bar"));
152: }
153:
154: public void testGroupDefinitionsWithMultipleREs() {
155: Collection groups;
156:
157: groups = config.getGroups("foobar");
158: assertEquals(0, groups.size());
159:
160: config.addGroupDefinition("foo", "/foo/");
161: config.addGroupDefinition("foo", "/bar/");
162:
163: groups = config.getGroups("foo only");
164: assertEquals(1, groups.size());
165: assertTrue(groups.contains("foo"));
166:
167: groups = config.getGroups("bar only");
168: assertEquals(1, groups.size());
169: assertTrue(groups.contains("foo"));
170: }
171: }
|