Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 235   Methods: 19
NCLOC: 130   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestNbSubMetricsMeasurement.java - 100% 63.2% 93.2%
coverage coverage
 1    /*
 2    * Copyright (c) 2001-2009, 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    public class TestNbSubMetricsMeasurement extends TestCase implements MeasurementVisitor {
 38    private MeasurementDescriptor descriptor;
 39    private NbSubMetricsMeasurement measurement;
 40    private Metrics metrics;
 41    private Measurement visited;
 42   
 43  10 protected void setUp() {
 44  10 metrics = new Metrics("foo");
 45   
 46  10 descriptor = new MeasurementDescriptor();
 47  10 descriptor.setShortName("foo");
 48  10 descriptor.setLongName("bar");
 49  10 descriptor.setClassFor(NbSubMetricsMeasurement.class);
 50  10 descriptor.setCached(false);
 51    }
 52   
 53  1 public void testCreateFromMeasurementDescriptor() throws Exception {
 54  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement();
 55   
 56  1 assertNotNull(measurement);
 57  1 assertEquals(descriptor, measurement.getDescriptor());
 58  1 assertSame(descriptor, measurement.getDescriptor());
 59  1 assertEquals(NbSubMetricsMeasurement.class, measurement.getClass());
 60  1 assertEquals("foo", measurement.getShortName());
 61  1 assertEquals("bar", measurement.getLongName());
 62    }
 63   
 64  1 public void testAddSubMetrics() throws Exception {
 65  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 66   
 67  1 assertEquals(0, measurement.getValue().intValue());
 68  1 assertEquals(0.0, measurement.getValue().doubleValue(), 0.01);
 69  1 assertEquals(0, measurement.getValue().intValue());
 70   
 71  1 metrics.addSubMetrics(new Metrics("bar"));
 72   
 73  1 assertEquals(1, measurement.getValue().intValue());
 74  1 assertEquals(1.0, measurement.getValue().doubleValue(), 0.01);
 75  1 assertEquals(1, measurement.getValue().intValue());
 76   
 77  1 metrics.addSubMetrics(new Metrics("bar"));
 78   
 79  1 assertEquals(1, measurement.getValue().intValue());
 80  1 assertEquals(1.0, measurement.getValue().doubleValue(), 0.01);
 81  1 assertEquals(1, measurement.getValue().intValue());
 82   
 83  1 metrics.addSubMetrics(new Metrics("baz"));
 84   
 85  1 assertEquals(2, measurement.getValue().intValue());
 86  1 assertEquals(2.0, measurement.getValue().doubleValue(), 0.01);
 87  1 assertEquals(2, measurement.getValue().intValue());
 88    }
 89   
 90  1 public void testInUndefinedRange() throws Exception {
 91  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 92   
 93  1 assertTrue(measurement.isInRange());
 94   
 95  1 metrics.addSubMetrics(new Metrics("foo"));
 96   
 97  1 assertTrue(measurement.isInRange());
 98   
 99  1 metrics.addSubMetrics(new Metrics("bar"));
 100  1 metrics.addSubMetrics(new Metrics("baz"));
 101   
 102  1 assertTrue(measurement.isInRange());
 103    }
 104   
 105  1 public void testInOpenRange() throws Exception {
 106  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 107   
 108  1 assertTrue(measurement.isInRange());
 109   
 110  1 metrics.addSubMetrics(new Metrics("foo"));
 111   
 112  1 assertTrue(measurement.isInRange());
 113   
 114  1 metrics.addSubMetrics(new Metrics("bar"));
 115  1 metrics.addSubMetrics(new Metrics("baz"));
 116   
 117  1 assertTrue(measurement.isInRange());
 118    }
 119   
 120  1 public void testInLowerBoundRange() throws Exception {
 121  1 descriptor.setLowerThreshold(new Integer(1));
 122   
 123  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 124   
 125  1 assertTrue(!measurement.isInRange());
 126   
 127  1 metrics.addSubMetrics(new Metrics("foo"));
 128   
 129  1 assertTrue(measurement.isInRange());
 130   
 131  1 metrics.addSubMetrics(new Metrics("bar"));
 132  1 metrics.addSubMetrics(new Metrics("baz"));
 133   
 134  1 assertTrue(measurement.isInRange());
 135    }
 136   
 137  1 public void testInUpperBoundRange() throws Exception {
 138  1 descriptor.setUpperThreshold(new Float(1.5));
 139   
 140  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 141   
 142  1 assertTrue(measurement.isInRange());
 143   
 144  1 metrics.addSubMetrics(new Metrics("foo"));
 145   
 146  1 assertTrue(measurement.isInRange());
 147   
 148  1 metrics.addSubMetrics(new Metrics("bar"));
 149  1 metrics.addSubMetrics(new Metrics("baz"));
 150   
 151  1 assertTrue(!measurement.isInRange());
 152    }
 153   
 154  1 public void testInBoundRange() throws Exception {
 155  1 descriptor.setLowerThreshold(new Integer(1));
 156  1 descriptor.setUpperThreshold(new Float(1.5));
 157   
 158  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 159   
 160  1 assertTrue(!measurement.isInRange());
 161   
 162  1 metrics.addSubMetrics(new Metrics("foo"));
 163   
 164  1 assertTrue(measurement.isInRange());
 165   
 166  1 metrics.addSubMetrics(new Metrics("bar"));
 167  1 metrics.addSubMetrics(new Metrics("baz"));
 168   
 169  1 assertTrue(!measurement.isInRange());
 170    }
 171   
 172  1 public void testCachedValue() throws Exception {
 173  1 descriptor.setCached(true);
 174   
 175  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 176   
 177  1 assertEquals("empty metrics", 0, measurement.getValue().intValue());
 178   
 179  1 metrics.addSubMetrics(new Metrics("foo"));
 180  1 metrics.addSubMetrics(new Metrics("bar"));
 181  1 metrics.addSubMetrics(new Metrics("baz"));
 182   
 183  1 assertEquals("empty metrics", 0, measurement.getValue().intValue());
 184    }
 185   
 186  1 public void testAccept() throws Exception {
 187  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 188   
 189  1 visited = null;
 190  1 measurement.accept(this);
 191  1 assertSame(measurement, visited);
 192    }
 193   
 194  1 public void testEmpty() throws Exception {
 195  1 measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 196   
 197  1 assertTrue("Before AddSubMetrics()", measurement.isEmpty());
 198   
 199  1 metrics.addSubMetrics(new Metrics("foo"));
 200   
 201  1 assertFalse("After AddSubMetrics()", measurement.isEmpty());
 202    }
 203   
 204  0 public void visitStatisticalMeasurement(StatisticalMeasurement measurement) {
 205    // Do nothing
 206    }
 207   
 208  0 public void visitRatioMeasurement(RatioMeasurement measurement) {
 209    // Do nothing
 210    }
 211   
 212  1 public void visitNbSubMetricsMeasurement(NbSubMetricsMeasurement measurement) {
 213  1 visited = measurement;
 214    }
 215   
 216  0 public void visitCounterMeasurement(CounterMeasurement measurement) {
 217    // Do nothing
 218    }
 219   
 220  0 public void visitContextAccumulatorMeasurement(ContextAccumulatorMeasurement measurement) {
 221    // Do nothing
 222    }
 223   
 224  0 public void visitNameListMeasurement(NameListMeasurement measurement) {
 225    // Do nothing
 226    }
 227   
 228  0 public void visitSubMetricsAccumulatorMeasurement(SubMetricsAccumulatorMeasurement measurement) {
 229    // Do nothing
 230    }
 231   
 232  0 public void visitSumMeasurement(SumMeasurement measurement) {
 233    // Do nothing
 234    }
 235    }