Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 133   Methods: 6
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DumpTagHandler.java 75% 93.1% 100% 88.2%
coverage coverage
 1   
 package junit.extensions.xml.elements;
 2   
 
 3   
 import junit.extensions.xml.IXMLTestCase;
 4   
 import junit.extensions.xml.XMLException;
 5   
 
 6   
 import org.w3c.dom.Element;
 7   
 
 8   
 import java.awt.Component;
 9   
 import java.awt.Container;
 10   
 
 11   
 
 12   
 /**
 13   
  * This class will handle the processing of <dump> tags.
 14   
  *
 15   
  * <H3>Required Attributes</H3>
 16   
  * refid
 17   
  *
 18   
  * <H3>Optional attributes</H3>
 19   
  *    recursive - Default vaue true
 20   
  *
 21   
  * @author <a href="mailto:baylward@nexagent.com">Bruce Aylward : Nexagent Ltd.</a>
 22   
  */
 23   
 public class DumpTagHandler extends AbstractTagHandler {
 24   
     /**
 25   
      * Constructor for DumpTagHandler.
 26   
      *
 27   
      * @param element     The element to be processed.
 28   
      * @param testCase    The IXMLTestCase that uses this element.
 29   
      */
 30  7
     public DumpTagHandler(final Element element, final IXMLTestCase testCase) {
 31  7
         super(element, testCase);
 32   
     }
 33   
 
 34   
     /**
 35   
      * Dump the object specified by the refid.
 36   
      * @throws XMLException may be thrown.
 37   
      */
 38  6
     public void processElement() throws XMLException {
 39  6
         validateElement();
 40   
 
 41  6
         Object object = getXMLTestCase().getProperty(getRefId());
 42   
 
 43  6
         if (object == null) {
 44  0
             throw new XMLException("Referenced object could not be found",
 45   
                 null,
 46   
                 getElement(),
 47   
                 getTest().getPropertyCache());
 48  6
         } else if (!(object instanceof Component)) {
 49  0
             throw new XMLException("Referenced object is not java.awt.Component",
 50   
                 null,
 51   
                 getElement(),
 52   
                 getTest().getPropertyCache());
 53   
         }
 54   
 
 55  6
         dumpComponents(
 56   
             (Component) object,
 57   
             1,
 58   
             getRecursive());
 59   
     }
 60   
 
 61   
     /**
 62   
      * Validate that the refid is specified.
 63   
      * @throws XMLException if the refid is not specified.
 64   
      */
 65  6
     public void validateElement() throws XMLException {
 66   
         // do the default validations from the super class
 67  6
         super.validateElement();
 68   
 
 69   
         // check the element tag name
 70  6
         checkElementTagName(DUMP);
 71   
 
 72   
         // reqd attribute: refid
 73  6
         checkRequiredAttribute(REFID);
 74   
     }
 75   
 
 76   
     /**
 77   
      * Dumps the component and all its children to standard out.
 78   
      * @param parent The component to dump.
 79   
      * @param level The indentation level.
 80   
      * @param recursive True if the dump should be recursive.
 81   
      */
 82  12
     private static void dumpComponents(final Component parent, final int level,
 83   
         final boolean recursive) {
 84  12
         String indent = "";
 85   
 
 86  12
         for (int t = 0; t < level; t++) {
 87  28
             indent += "   ";
 88   
         }
 89   
 
 90  12
         String name = parent.getName();
 91   
 
 92  12
         if (name == null) {
 93  7
             name = "<anonymous>";
 94   
         }
 95   
 
 96  12
         System.out.println(indent + name + "(" + parent + ")");
 97   
 
 98  12
         if (parent instanceof Container) {
 99  12
             Component[] children = ((Container) parent).getComponents();
 100   
 
 101  12
             for (int t = 0; t < children.length; t++) {
 102  7
                 if (recursive) {
 103  6
                     dumpComponents(children[t], level + 1, recursive);
 104   
                 } else {
 105  1
                     name = children[t].getName();
 106   
 
 107  1
                     if (name == null) {
 108  1
                         name = "<anonymous>";
 109   
                     }
 110   
 
 111  1
                     System.out.println(indent + name + "(" + children[t] + ")");
 112   
                 }
 113   
             }
 114   
         }
 115   
     }
 116   
 
 117   
     /**
 118   
      * Returns the value of the RECURSIVE attribute for this element.
 119   
      * @return String  The value of the RECURSIVE attribute.
 120   
      */
 121  6
     private boolean getRecursive() {
 122  6
         return getBoolean(RECURSIVE, true);
 123   
     }
 124   
 
 125   
     /**
 126   
      * Returns the value of the REFID attribute for this element.
 127   
      * @return String  The value of the REFID attribute.
 128   
      */
 129  6
     private String getRefId() {
 130  6
         return getString(REFID);
 131   
     }
 132   
 }
 133