1 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 |