Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 91   Methods: 4
NCLOC: 32   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AssertEnabledTagHandler.java 100% 100% 100% 100%
coverage
 1   
 package junit.extensions.xml.elements;
 2   
 
 3   
 import junit.extensions.xml.IXMLTestCase;
 4   
 import junit.extensions.xml.XMLException;
 5   
 
 6   
 import junit.framework.Assert;
 7   
 
 8   
 import org.w3c.dom.Element;
 9   
 
 10   
 
 11   
 /**
 12   
  * This class will handle the processing of <assertenabled> nodes.
 13   
  *
 14   
  * <H3>Mandatory attributes</H3>
 15   
  *    refid Id of the property to be compared.
 16   
  *
 17   
  * <H3>Optional attributes (default value)</H3>
 18   
  *    message Message to be displayed when assertion fails.<br>
 19   
  *    enabled true or false. Default value is true.
 20   
  *
 21   
  * <H3>Examples:</H3>
 22   
  *    &lt;assertenabled refid=&quot;MyComponent&quot;
 23   
  *       message=&quot;Component is not enabled&quot;
 24   
  *       enabled=&quot;true&quot;/&gt;<br>
 25   
  *    &lt;assertenabled refid=&quot;MyComponent&quot;
 26   
  *       message=&quot;Component is enabled&quot;
 27   
  *       enabled=&quot;false&quot;/&gt;<br>
 28   
  *    &lt;assertenabled refid=&quot;MyComponent&quot;
 29   
  *       message=&quot;Component is not enabled&quot;/&gt;<br>
 30   
  *
 31   
  * @author <a href="mailto:baylward@nexagent.com">Bruce Aylward : Nexagent Ltd.</a>
 32   
  */
 33   
 public class AssertEnabledTagHandler extends AbstractAssertTagHandler {
 34   
     /**
 35   
      * Constructor for AssertEnabledTagHandler.
 36   
      *
 37   
      * @param element     The element to be processed
 38   
      * @param testCase    The IXMLTestCase that uses this element
 39   
      */
 40  6
     public AssertEnabledTagHandler(final Element element,
 41   
         final IXMLTestCase testCase) {
 42  6
         super(element, testCase);
 43   
     }
 44   
 
 45   
     /**
 46   
      * This method obtains the refid which is assumed to
 47   
      * be a java.awt.Component. The enabled method is tested
 48   
      * and compared with test enabed attribute if specified.
 49   
      * If enabled is not specified it is assumed to be true.
 50   
      *
 51   
      * @throws XMLException may be thrown.
 52   
      */
 53  5
     public void processElement() throws XMLException {
 54  5
         validateElement();
 55   
 
 56  5
         boolean result = false;
 57  5
         Object  object = getXMLTestCase().getProperty(getRefId());
 58  5
         Assert.assertNotNull(
 59   
             getMessage(),
 60   
             object);
 61   
 
 62  5
         if (object instanceof java.awt.Component) {
 63  4
             result = ((java.awt.Component) object).isEnabled();
 64   
         }
 65   
 
 66  5
         Assert.assertTrue(
 67   
             getMessage(),
 68   
             result == getEnabled());
 69   
     }
 70   
 
 71   
     /**
 72   
      * Validate the element has a refid.
 73   
      * @throws XMLException when the refid is not specified.
 74   
      */
 75  5
     public void validateElement() throws XMLException {
 76   
         // do the default validations from the super class
 77  5
         super.validateElement();
 78   
 
 79   
         // reqd attribute: refid
 80  5
         checkRequiredAttribute(REFID);
 81   
     }
 82   
 
 83   
     /**
 84   
      * Returns the value of the ENABLED attribute for this element.
 85   
      * @return String  The value of the ENABLED attribute.
 86   
      */
 87  5
     private boolean getEnabled() {
 88  5
         return getBoolean(ENABLED, true);
 89   
     }
 90   
 }
 91