Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 152   Methods: 4
NCLOC: 98   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DragTagHandler.java 72.2% 65.1% 75% 67.7%
coverage coverage
 1   
 package junit.extensions.jfcunit.eventdata;
 2   
 
 3   
 import junit.extensions.jfcunit.xml.JFCXMLConstants;
 4   
 import junit.extensions.jfcunit.xml.JFCXMLTestCase;
 5   
 
 6   
 import junit.extensions.xml.IXMLTestCase;
 7   
 import junit.extensions.xml.XMLException;
 8   
 import junit.extensions.xml.XMLTagResourceBundle;
 9   
 import junit.extensions.xml.XMLUtil;
 10   
 import junit.extensions.xml.elements.AbstractTagHandler;
 11   
 
 12   
 import org.w3c.dom.Element;
 13   
 import org.w3c.dom.NodeList;
 14   
 
 15   
 import java.awt.Point;
 16   
 
 17   
 import java.text.MessageFormat;
 18   
 
 19   
 import java.util.Vector;
 20   
 
 21   
 
 22   
 /**
 23   
  * This class will handle the processing of <click> nodes.
 24   
  *
 25   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 26   
  */
 27   
 public class DragTagHandler extends AbstractTagHandler
 28   
     implements JFCXMLConstants {
 29   
     /**
 30   
      * Constructor for ClickTagHandler.
 31   
      *
 32   
      * @param element     The element to be processed
 33   
      * @param testCase    The IXMLTestCase that uses this element
 34   
      */
 35  2
     public DragTagHandler(final Element element, final IXMLTestCase testCase) {
 36  2
         super(element, testCase);
 37   
     }
 38   
 
 39   
     /**
 40   
      * @see junit.extensions.xml.elements.AbstractTagHandler#processElement()
 41   
      * @throws XMLException when element cannot be properly parsed.
 42   
      */
 43  2
     public void processElement() throws XMLException {
 44  2
         validateElement();
 45   
 
 46  2
         AbstractMouseEventData source = null;
 47  2
         AbstractMouseEventData dest   = null;
 48  2
         Vector                 points = new Vector();
 49  2
         JFCXMLTestCase         tc     = (JFCXMLTestCase) getTestCase();
 50   
 
 51   
         // now we are ready to handle each individual node/element
 52   
         // Get the children and add to the suite.
 53  2
         NodeList children = getElement().getChildNodes();
 54  2
         Element  child;
 55   
 
 56  2
         for (int i = 0; i < children.getLength(); i++) {
 57  10
             if (children.item(i) instanceof Element) {
 58  4
                 child = (Element) children.item(i);
 59   
 
 60  4
                 String name = child.getTagName();
 61   
 
 62  4
                 if (name.equals(POINT)) {
 63  0
                     String        data = XMLUtil.getAttribute(child, REFERENCE);
 64  0
                     MessageFormat mf = new MessageFormat("{0},{1}");
 65  0
                     int           x  = 0;
 66  0
                     int           y  = 0;
 67   
 
 68  0
                     try {
 69  0
                         Object[] obs = mf.parse(data);
 70  0
                         x     = Integer.parseInt((String) obs[0]);
 71  0
                         y     = Integer.parseInt((String) obs[1]);
 72   
                     } catch (Exception ex) {
 73  0
                         throw new XMLException("Could not parse the point:"
 74   
                             + data, ex,
 75   
                             getElement(),
 76   
                             getXMLTestCase().getPropertyCache());
 77   
                     }
 78   
 
 79  0
                     points.add(new Point(x, y));
 80   
                 }
 81   
 
 82  4
                 if (name.equals(DESTINATION)) {
 83  2
                     if (dest != null) {
 84  0
                         throw new XMLException("Destination specified twice",
 85   
                             null,
 86   
                             getElement(),
 87   
                             getXMLTestCase().getPropertyCache());
 88   
                     }
 89   
 
 90  2
                     String                  type = XMLUtil.getAttribute(child,
 91   
                             TYPE);
 92  2
                     BaseEventDataTagHandler th = (BaseEventDataTagHandler) XMLTagResourceBundle
 93   
                         .getTagHandler(
 94   
                             child,
 95   
                             getXMLTestCase(),
 96   
                             type);
 97  2
                     dest = th.getEventData();
 98   
                 }
 99   
 
 100  4
                 if (name.equals(SOURCE)) {
 101  2
                     if (source != null) {
 102  0
                         throw new XMLException("Source specified twice", null,
 103   
                             getElement(),
 104   
                             getXMLTestCase().getProcedureCache());
 105   
                     }
 106   
 
 107  2
                     String                  type = XMLUtil.getAttribute(child,
 108   
                             TYPE);
 109  2
                     BaseEventDataTagHandler th = (BaseEventDataTagHandler) XMLTagResourceBundle
 110   
                         .getTagHandler(
 111   
                             child,
 112   
                             getXMLTestCase(),
 113   
                             type);
 114  2
                     source = th.getEventData();
 115   
                 }
 116   
             }
 117   
         }
 118   
 
 119  2
         if (source == null) {
 120  0
             throw new XMLException("Source not specified in drag.", null,
 121   
                 getElement(),
 122   
                 getXMLTestCase().getPropertyCache());
 123   
         }
 124   
 
 125   
         // We have what we need to construct the event.
 126  2
         DragEventData dragEvent = new DragEventData(tc, source, dest);
 127   
 
 128  2
         if (points.size() > 0) {
 129  0
             dragEvent.setPoints((Point[]) points.toArray(new Point[0]));
 130   
         }
 131   
 
 132  2
         tc.getHelper().enterDragAndLeave(dragEvent);
 133   
     }
 134   
 
 135   
     /**
 136   
      * @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
 137   
      * @throws XMLException when element cannot be properly parsed.
 138   
      */
 139  2
     public void validateElement() throws XMLException {
 140   
         // do the default validations from the super class
 141  2
         super.validateElement();
 142   
     }
 143   
 
 144   
     /**
 145   
      * Returns the value of the TYPE attribute for this element.
 146   
      * @return String  The value of the TYPE attribute.
 147   
      */
 148  0
     protected final String getType() {
 149  0
         return getString(TYPE);
 150   
     }
 151   
 }
 152