Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 85   Methods: 4
NCLOC: 33   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SleepTagHandler.java 50% 75% 100% 75%
coverage coverage
 1   
 package junit.extensions.jfcunit.xml;
 2   
 
 3   
 import junit.extensions.jfcunit.JFCTestCase;
 4   
 
 5   
 import junit.extensions.xml.IXMLTestCase;
 6   
 import junit.extensions.xml.XMLException;
 7   
 import junit.extensions.xml.elements.AbstractTagHandler;
 8   
 
 9   
 import org.w3c.dom.Element;
 10   
 
 11   
 
 12   
 /**
 13   
  * This class will handle causes the test case to sleep
 14   
  * and allows the AWTEventQueue to run for the specified
 15   
  * number of milliseconds.
 16   
  *
 17   
  * <H3>Tag Name</H3>
 18   
  * sleep
 19   
  * <H3>Required Attribute</H3>
 20   
  * duration - number of milliseconds to sleep or
 21   
  *            "forever" to sleep forever.
 22   
  * <H3>Examples</H3>
 23   
  * Sleep for 1 second.
 24   
  * <pre>
 25   
  * &lt;sleep duration="1000"/&gt
 26   
  * </pre>
 27   
  * Sleep forever
 28   
  * <pre>
 29   
  * &lt;sleep duration="forever"/&gt
 30   
  * </pre>
 31   
  * @author <a href="mailto:klwilson227@users.sourceforge.net">Kevin L Wilson</a>
 32   
  */
 33   
 public class SleepTagHandler extends AbstractTagHandler
 34   
     implements JFCXMLConstants {
 35   
     /**
 36   
      * Constructor for AWTThreadTagHandler.
 37   
      *
 38   
      * @param element     The element to be processed
 39   
      * @param testCase    The IXMLTestCase that uses this element
 40   
      */
 41  35
     public SleepTagHandler(final Element element, final IXMLTestCase testCase) {
 42  35
         super(element, testCase);
 43   
     }
 44   
 
 45   
     /**
 46   
      * @see junit.extensions.xml.elements.AbstractTagHandler#processElement()
 47   
      */
 48  35
     public void processElement() throws XMLException {
 49  35
         validateElement();
 50   
 
 51  35
         long sleep = getSleepTime();
 52   
 
 53  35
         if (sleep >= 0) {
 54  35
             ((JFCTestCase) getTestCase()).sleep(sleep);
 55   
         } else {
 56  0
             for (;;) {
 57  0
                 ((JFCTestCase) getTestCase()).sleep(10000);
 58   
             }
 59   
         }
 60   
     }
 61   
 
 62   
     /**
 63   
      * @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
 64   
      */
 65  35
     public void validateElement() throws XMLException {
 66   
         // do the default validations from the super class
 67  35
         super.validateElement();
 68   
 
 69  35
         checkRequiredAttribute(DURATION);
 70   
     }
 71   
 
 72   
     /**
 73   
      * Returns the value of the SLEEPTIME attribute for this element, DEFAULT_SLEEPTIME if nothing
 74   
      * was specified.
 75   
      * @return long    The sleepTime for this element.
 76   
      */
 77  35
     protected long getSleepTime() {
 78  35
         if ("forever".equals(getString(DURATION))) {
 79  0
             return -1;
 80   
         }
 81   
 
 82  35
         return getLong(DURATION, DEFAULT_SLEEPTIME);
 83   
     }
 84   
 }
 85