Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 217   Methods: 12
NCLOC: 142   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestNbSubMetricsMeasurementSelectionCriteria.java - 100% 100% 100%
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 java.util.*;
 36   
 37    import org.apache.oro.text.perl.*;
 38   
 39    import junit.framework.*;
 40   
 41    public class TestNbSubMetricsMeasurementSelectionCriteria extends TestCase {
 42    private Metrics metrics;
 43    private MeasurementDescriptor descriptor;
 44   
 45    private Metrics m1;
 46    private Metrics m2;
 47    private Metrics m3;
 48    private Metrics m4;
 49    private Metrics m5;
 50    private Metrics m6;
 51   
 52  11 protected void setUp() throws Exception {
 53  11 m1 = new Metrics("m1");
 54  11 m2 = new Metrics("m2");
 55  11 m3 = new Metrics("m3");
 56  11 m4 = new Metrics("m4");
 57  11 m5 = new Metrics("m5");
 58  11 m6 = new Metrics("m6");
 59   
 60  11 MeasurementDescriptor present = new MeasurementDescriptor();
 61  11 present.setShortName("P");
 62  11 present.setLongName("present");
 63  11 present.setClassFor(CounterMeasurement.class);
 64   
 65  11 MeasurementDescriptor counter = new MeasurementDescriptor();
 66  11 counter.setShortName("C");
 67  11 counter.setLongName("counter");
 68  11 counter.setClassFor(CounterMeasurement.class);
 69   
 70  11 m1.track(present.createMeasurement(m1));
 71   
 72  11 m2.track(present.createMeasurement(m2));
 73  11 m2.track(counter.createMeasurement(m2));
 74  11 m2.addToMeasurement("C", 0);
 75   
 76  11 m3.track(counter.createMeasurement(m3));
 77  11 m3.addToMeasurement("C", 1);
 78   
 79  11 m4.track(counter.createMeasurement(m4));
 80  11 m4.addToMeasurement("C", 2);
 81   
 82  11 m5.track(counter.createMeasurement(m5));
 83  11 m5.addToMeasurement("C", 3);
 84   
 85  11 m6.track(counter.createMeasurement(m6));
 86  11 m6.addToMeasurement("C", 4);
 87   
 88  11 metrics = new Metrics("metrics");
 89   
 90  11 metrics.addSubMetrics(m1);
 91  11 metrics.addSubMetrics(m2);
 92  11 metrics.addSubMetrics(m3);
 93  11 metrics.addSubMetrics(m4);
 94  11 metrics.addSubMetrics(m5);
 95  11 metrics.addSubMetrics(m6);
 96   
 97  11 descriptor = new MeasurementDescriptor();
 98  11 descriptor.setShortName("Nb");
 99  11 descriptor.setLongName("Number");
 100  11 descriptor.setClassFor(NbSubMetricsMeasurement.class);
 101    }
 102   
 103  1 public void testDefault() throws Exception {
 104  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 105  1 assertEquals("default", 6, measurement.getValue().intValue());
 106    }
 107   
 108  1 public void testPresence() throws Exception {
 109  1 descriptor.setInitText("P");
 110   
 111  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 112  1 assertEquals("presence", 2, measurement.getValue().intValue());
 113    }
 114   
 115  1 public void testLesserThan() throws Exception {
 116  1 descriptor.setInitText("C < 3");
 117   
 118  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 119  1 assertEquals("lesser than", 3, measurement.getValue().intValue());
 120    }
 121   
 122  1 public void testLesserThanOrEqual() throws Exception {
 123  1 descriptor.setInitText("C <= 3");
 124   
 125  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 126  1 assertEquals("lesser than or equal", 4, measurement.getValue().intValue());
 127    }
 128   
 129  1 public void testGreaterThan() throws Exception {
 130  1 descriptor.setInitText("C > 1");
 131   
 132  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 133  1 assertEquals("greater than", 3, measurement.getValue().intValue());
 134    }
 135   
 136  1 public void testGreaterThanOrEqual() throws Exception {
 137  1 descriptor.setInitText("C >= 1");
 138   
 139  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 140  1 assertEquals("greater than or equal", 4, measurement.getValue().intValue());
 141    }
 142   
 143  1 public void testEqual() throws Exception {
 144  1 descriptor.setInitText("C == 1");
 145   
 146  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 147  1 assertEquals("equal", 1, measurement.getValue().intValue());
 148    }
 149   
 150  1 public void testNotEqual() throws Exception {
 151  1 descriptor.setInitText("C != 1");
 152   
 153  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 154  1 assertEquals("not equal", 4, measurement.getValue().intValue());
 155    }
 156   
 157  1 public void testAnd() throws Exception {
 158  1 descriptor.setInitText("1 <= C <= 3");
 159   
 160  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 161  1 assertEquals("and", 3, measurement.getValue().intValue());
 162    }
 163   
 164  1 public void testOr() throws Exception {
 165  1 descriptor.setInitText("C == 1\nC == 2");
 166   
 167  1 NbSubMetricsMeasurement measurement = (NbSubMetricsMeasurement) descriptor.createMeasurement(metrics);
 168  1 assertEquals("or", 2, measurement.getValue().intValue());
 169    }
 170   
 171  1 public void testSplit() {
 172  1 String operators = "/(<)|(<=)|(>)|(>=)|(==)|(!=)/";
 173  1 Perl5Util perl = new org.apache.oro.text.perl.Perl5Util();
 174   
 175  1 List list = new ArrayList();
 176  1 String str;
 177   
 178  1 list.clear();
 179  1 str = "";
 180  1 perl.split(list, operators, str);
 181  1 assertEquals("split(\"" + str + "\") expected [] but was " + list, 0, list.size());
 182   
 183  1 list.clear();
 184  1 str = "P";
 185  1 perl.split(list, operators, str);
 186  1 assertEquals("split(\"" + str + "\") expected [\"P\"] but was " + list, 1, list.size());
 187  1 assertEquals("split(\"" + str + "\") expected [\"P\"] but was " + list, str, list.get(0));
 188   
 189  1 list.clear();
 190  1 str = "P > 0";
 191  1 perl.split(list, operators, str);
 192  1 assertEquals("split(\"" + str + "\") expected [\"P \", \">\", \" 0\"] but was " + list, 3, list.size());
 193  1 assertEquals("split(\"" + str + "\") expected [\"P \", \">\", \" 0\"] but was " + list, "P ", list.get(0));
 194  1 assertEquals("split(\"" + str + "\") expected [\"P \", \">\", \" 0\"] but was " + list, ">", list.get(1));
 195  1 assertEquals("split(\"" + str + "\") expected [\"P \", \">\", \" 0\"] but was " + list, " 0", list.get(2));
 196   
 197  1 list.clear();
 198  1 str = "1 < P < 3";
 199  1 perl.split(list, operators, str);
 200  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P \", \"<\", \" 3\"] but was " + list, 5, list.size());
 201  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P \", \"<\", \" 3\"] but was " + list, "1 ", list.get(0));
 202  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P \", \"<\", \" 3\"] but was " + list, "<", list.get(1));
 203  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P \", \"<\", \" 3\"] but was " + list, " P ", list.get(2));
 204  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P \", \"<\", \" 3\"] but was " + list, "<", list.get(3));
 205  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P \", \"<\", \" 3\"] but was " + list, " 3", list.get(4));
 206   
 207  1 list.clear();
 208  1 str = "1 < P DISPOSE_MEAN < 3";
 209  1 perl.split(list, operators, str);
 210  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P DISPOSE_MEAN \", \"<\", \" 3\"] but was " + list, 5, list.size());
 211  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P DISPOSE_MEAN \", \"<\", \" 3\"] but was " + list, "1 ", list.get(0));
 212  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P DISPOSE_MEAN \", \"<\", \" 3\"] but was " + list, "<", list.get(1));
 213  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P DISPOSE_MEAN \", \"<\", \" 3\"] but was " + list, " P DISPOSE_MEAN ", list.get(2));
 214  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P DISPOSE_MEAN \", \"<\", \" 3\"] but was " + list, "<", list.get(3));
 215  1 assertEquals("split(\"" + str + "\") expected [\"1 \", \"<\", \" P DISPOSE_MEAN \", \"<\", \" 3\"] but was " + list, " 3", list.get(4));
 216    }
 217    }