Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 220   Methods: 19
NCLOC: 97   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JUnitTest.java 62.5% 69.2% 84.2% 72.7%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 
 55   
 package org.apache.tools.ant.taskdefs.optional.junit;
 56   
 
 57   
 import java.util.Enumeration;
 58   
 import java.util.Hashtable;
 59   
 import java.util.Properties;
 60   
 import java.util.Vector;
 61   
 import org.apache.tools.ant.Project;
 62   
 
 63   
 /**
 64   
  * <p> Run a single JUnit test.
 65   
  *
 66   
  * <p> The JUnit test is actually run by {@link JUnitTestRunner}.
 67   
  * So read the doc comments for that class :)
 68   
  *
 69   
  * @author Thomas Haas
 70   
  * @author Stefan Bodewig,
 71   
  * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
 72   
  *
 73   
  * @since Ant 1.2
 74   
  *
 75   
  * @see JUnitTask
 76   
  * @see JUnitTestRunner
 77   
  */
 78   
 public class JUnitTest extends BaseTest implements Cloneable {
 79   
     
 80   
     /** the name of the test case */
 81   
     private String name = null;
 82   
     
 83   
     /** the name of the result file */
 84   
     private String outfile = null;
 85   
 
 86   
     // @todo this is duplicating TestResult information. Only the time is not
 87   
     // part of the result. So we'd better derive a new class from TestResult
 88   
     // and deal with it. (SB)
 89   
     private long runs, failures, errors;
 90   
     private long runTime;
 91   
 
 92   
     // Snapshot of the system properties
 93   
     private Properties props = null;
 94   
 
 95  136
     public JUnitTest() {
 96   
     }
 97   
 
 98  5
     public JUnitTest(String name) {
 99  5
         this.name  = name;
 100   
     }
 101   
 
 102  0
     public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure, 
 103   
                      boolean filtertrace) {
 104  0
         this.name  = name;
 105  0
         this.haltOnError = haltOnError;
 106  0
         this.haltOnFail = haltOnFailure;
 107  0
         this.filtertrace = filtertrace;
 108   
     }
 109   
 
 110   
     /** 
 111   
      * Set the name of the test class.
 112   
      */
 113  136
     public void setName(String value) {
 114  136
         name = value;
 115   
     }
 116   
 
 117   
     /**
 118   
      * Set the name of the output file.
 119   
      */
 120  136
     public void setOutfile(String value) {
 121  136
         outfile = value;
 122   
     }
 123   
 
 124   
     /** 
 125   
      * Get the name of the test class.
 126   
      */
 127  415
     public String getName() {
 128  415
         return name;
 129   
     }
 130   
 
 131   
     /**
 132   
      * Get the name of the output file
 133   
      * 
 134   
      * @return the name of the output file.
 135   
      */
 136  136
     public String getOutfile() {
 137  136
         return outfile;
 138   
     }
 139   
 
 140  141
     public void setCounts(long runs, long failures, long errors) {
 141  141
         this.runs = runs;
 142  141
         this.failures = failures;
 143  141
         this.errors = errors;
 144   
     }
 145   
 
 146  141
     public void setRunTime(long runTime) {
 147  141
         this.runTime = runTime;
 148   
     }
 149   
 
 150  136
     public long runCount() {
 151  136
         return runs;
 152   
     }
 153   
     
 154  136
     public long failureCount() {
 155  136
         return failures;
 156   
     }
 157   
     
 158  136
     public long errorCount() {
 159  136
         return errors;
 160   
     }
 161   
     
 162  136
     public long getRunTime() {
 163  136
         return runTime;
 164   
     }
 165   
 
 166  0
     public Properties getProperties() {
 167  0
         return props;
 168   
     }
 169   
     
 170  136
     public void setProperties(Hashtable p) { 
 171  136
         props = new Properties();  
 172  136
         for (Enumeration enum = p.keys(); enum.hasMoreElements();) {
 173  25930
             Object key = enum.nextElement();
 174  25930
             props.put(key, p.get(key));
 175   
         }
 176   
     }
 177   
 
 178  136
     public boolean shouldRun(Project p) {
 179  136
         if (ifProperty != null && p.getProperty(ifProperty) == null) {
 180  0
             return false;
 181  136
         } else if (unlessProperty != null && 
 182   
                    p.getProperty(unlessProperty) != null) {
 183  0
             return false;
 184   
         }
 185   
 
 186  136
         return true;
 187   
     }
 188   
 
 189  0
     public FormatterElement[] getFormatters() {
 190  0
         FormatterElement[] fes = new FormatterElement[formatters.size()];
 191  0
         formatters.copyInto(fes);
 192  0
         return fes;
 193   
     }
 194   
 
 195   
     /**
 196   
      * Convenient method to add formatters to a vector
 197   
      */
 198  136
     void addFormattersTo(Vector v){
 199  136
         final int count = formatters.size();
 200  136
         for (int i = 0; i < count; i++){
 201  0
             v.addElement(formatters.elementAt(i));
 202   
         }
 203   
     }
 204   
 
 205   
     /**
 206   
      * @since Ant 1.5
 207   
      */
 208  272
     public Object clone() {
 209  272
         try {
 210  272
             JUnitTest t = (JUnitTest) super.clone();
 211  272
             t.props = props == null ? null : (Properties) props.clone();
 212  272
             t.formatters = (Vector) formatters.clone();
 213  272
             return t;
 214   
         } catch (CloneNotSupportedException e) {
 215   
             // plain impossible
 216  0
             return this;
 217   
         }
 218   
     }
 219   
 }
 220