Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 138   Methods: 3
NCLOC: 29   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NamedComponentFinderTagHandler.java - 100% 100% 100%
coverage
 1   
 package junit.extensions.jfcunit.finder;
 2   
 
 3   
 import junit.extensions.xml.IXMLTestCase;
 4   
 import junit.extensions.xml.XMLException;
 5   
 
 6   
 import org.w3c.dom.Element;
 7   
 
 8   
 
 9   
 /**
 10   
  * This is a extension of the findTagHandler element. Where the
 11   
  * finder specified is NamedComponentFinder.
 12   
  *
 13   
  * <h3>Description</h3>
 14   
  * <p>
 15   
  *   This creates a NamedComponentFinder and executes the find.
 16   
  * </p>
 17   
  * <h3>Finder tag name</h3>
 18   
  * <p>
 19   
  * NamedComponentFinder
 20   
  * </p>
 21   
  * <h3>Parameters</h3>
 22   
  * <table border="1" cellpadding="2" cellspacing="0">
 23   
  *   <tr>
 24   
  *     <td valign="top"><b>Attribute</b></td>
 25   
  *     <td valign="top"><b>Description</b></td>
 26   
  *     <td align="center" valign="top"><b>Required</b></td>
 27   
  *     <td valign="top"><b>Default</b></td>
 28   
  *     <td valign="top"><b>Values</b></td>
 29   
  *   </tr>
 30   
  *   <tr>
 31   
  *     <td valign="top">finder</td>
 32   
  *     <td valign="top">For this element the type must be set to NamedComponentFinder</td>
 33   
  *     <td valign="top" align="center">Yes</td>
 34   
  *     <td valign="top">N/A</td>
 35   
  *     <td valign="top">N/A</td>
 36   
  *   </tr>
 37   
  *   <tr>
 38   
  *     <td valign="top">id</td>
 39   
  *     <td valign="top">Id for the object found.</td>
 40   
  *     <td valign="top" align="center">Yes</td>
 41   
  *     <td valign="top">N/A</td>
 42   
  *     <td valign="top">String</td>
 43   
  *   </tr>
 44   
  *   <tr>
 45   
  *     <td valign="top">refid</td>
 46   
  *     <td valign="top">Id for the object found.</td>
 47   
  *     <td valign="top" align="center">No</td>
 48   
  *     <td valign="top">Search in all windows</td>
 49   
  *     <td valign="top">Panel to be searched</td>
 50   
  *   </tr>
 51   
  *   <tr>
 52   
  *     <td valign="top">index</td>
 53   
  *     <td valign="top">The index of the element to select from the combo box.</td>
 54   
  *     <td valign="top" align="center">Yes</td>
 55   
  *     <td valign="top">N/A</td>
 56   
  *     <td valign="top">Zero based index of list items.</td>
 57   
  *   </tr>
 58   
  *   <tr>
 59   
  *     <td valign="top">name</td>
 60   
  *     <td valign="top">The name of the component to be found.</td>
 61   
  *     <td valign="top" align="center">Yes</td>
 62   
  *     <td valign="top">None</td>
 63   
  *     <td valign="top">Name of the component.</td>
 64   
  *   </tr>
 65   
  *   <tr>
 66   
  *     <td valign="top">caseindependent</td>
 67   
  *     <td valign="top">Ignore the case if true</td>
 68   
  *     <td valign="top" align="center">No</td>
 69   
  *     <td valign="top">false</td>
 70   
  *     <td valign="top">true/false</td>
 71   
  *   </tr>
 72   
  * </table>
 73   
  * <h3>Example</h3>
 74   
  * <blockquote><pre>
 75   
  * &lt;find
 76   
  *    finder=&quot;NamedComponentFinder&quot;
 77   
  *    id=&quot;NamedComponent&quot;
 78   
  *    class=&quot;javax.swing.JButton&quot;
 79   
  *    name=&quot;MyName&quot;
 80   
  *    index=&quot;0&quot;
 81   
  * /&gt;
 82   
  * </pre></blockquote>
 83   
  * <p>
 84   
  * The above finds the JButton identified &quot;MyName&quot;
 85   
  * </p>
 86   
  * @see junit.extensions.jfcunit.finder.NamedComponentFinder
 87   
  * @author Kevin Wilson
 88   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 89   
  */
 90   
 public class NamedComponentFinderTagHandler extends BaseFindTagHandler {
 91   
     /**
 92   
      * Constructor for FindTagHandler.
 93   
      *
 94   
      * @param element     The element to be processed
 95   
      * @param testCase    The IXMLTestCase that uses this element
 96   
      */
 97  2
     public NamedComponentFinderTagHandler(final Element element,
 98   
         final IXMLTestCase testCase) {
 99  2
         super(element, testCase);
 100   
     }
 101   
 
 102   
     /**
 103   
      * @see junit.extensions.xml.elements.AbstractTagHandler#processElement()
 104   
      * @throws XMLException is thrown if the element cannot be understood.
 105   
      */
 106  2
     public void processElement() throws XMLException {
 107  2
         validateElement();
 108   
 
 109  2
         String  name            = getName();
 110  2
         String  clazzName       = getClassName();
 111  2
         boolean caseIndependent = getCaseIndependent();
 112   
 
 113  2
         try {
 114  2
             Class clazz = Class.forName(clazzName);
 115  1
             find(new NamedComponentFinder(clazz, name, caseIndependent));
 116   
         } catch (ClassNotFoundException ex) {
 117  1
             throw new XMLException("Could not find class:" + clazzName, ex,
 118   
                 getElement(),
 119   
                 getXMLTestCase().getPropertyCache());
 120   
         }
 121   
     }
 122   
 
 123   
     /**
 124   
      * @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
 125   
      * @throws XMLException when errors encountered processing XML.
 126   
      */
 127  2
     public void validateElement() throws XMLException {
 128   
         // do the default validations from the super class
 129  2
         super.validateElement();
 130   
 
 131   
         // reqd attribute: name
 132  2
         checkRequiredAttribute(NAME);
 133   
 
 134   
         // reqd attribute: class
 135  2
         checkRequiredAttribute(CLASS);
 136   
     }
 137   
 }
 138