Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 88   Methods: 3
NCLOC: 33   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AssertEqualsTagHandler.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 <assertequal> nodes.
 13   
  * Insures that the actual and expected objects are equal.
 14   
  * <H3>Summary</H3>
 15   
  * &lt;assertequal [message="message text"] actualrefid="id"|actualobj="value"
 16   
  *  expectedrefid="id"|expectedobj="value"/&gt;
 17   
  *
 18   
  * <H3>One of the following attributes are required:</H3>
 19   
  *   actualrefid  id of the object to be compared.<br>
 20   
  *   actualobj value of the object to be compared.
 21   
  *
 22   
  * <H3>One of the following attributes are required:</H3>
 23   
  *   expectedrefid id of the object to be compared.<br>
 24   
  *   expectedobj value of the object to be compared.
 25   
  *
 26   
  * <H3>Optional Attributes:</H3>
 27   
  *   message Optional message text to be displayed in assertion.
 28   
  *
 29   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 30   
  */
 31   
 public class AssertEqualsTagHandler extends AbstractAssertTagHandler {
 32   
     /**
 33   
      * Constructor for AssertEqualsTagHandler.
 34   
      *
 35   
      * @param element     The element to be processed
 36   
      * @param testCase    The IXMLTestCase that uses this element
 37   
      */
 38  17
     public AssertEqualsTagHandler(final Element element,
 39   
         final IXMLTestCase testCase) {
 40  17
         super(element, testCase);
 41   
     }
 42   
 
 43   
     /**
 44   
      * Obtain the expected and actual objects. Then
 45   
      * test if one of the objects is a string. If so
 46   
      * the call toString() to normalize both objects
 47   
      * to a string. Assert that the values of the
 48   
      * actual and the expected are equal.
 49   
      *
 50   
      * @throws XMLException upon assertion failure.
 51   
      */
 52  16
     public void processElement() throws XMLException {
 53  16
         validateElement();
 54   
 
 55  15
         Object expected = getExpectedObject();
 56  15
         Object actual = getActualObject();
 57   
 
 58  15
         if (expected instanceof String || actual instanceof String) {
 59  13
             if (actual != null) {
 60  12
                 actual = actual.toString();
 61   
             }
 62   
 
 63  13
             if (expected != null) {
 64  12
                 expected = expected.toString();
 65   
             }
 66   
         }
 67   
 
 68  15
         Assert.assertEquals(
 69   
             getMessage(),
 70   
             expected,
 71   
             actual);
 72   
     }
 73   
 
 74   
     /**
 75   
      * Insure that the element contains a Actual and expected
 76   
      * attribute.
 77   
      * @throws XMLException Thrown if a required attribute is missing.
 78   
      */
 79  16
     public void validateElement() throws XMLException {
 80   
         // do the default validations from the super class
 81  16
         super.validateElement();
 82   
 
 83   
         // reqd attribute: at least one of expected or expectedrefid
 84  16
         checkExpected();
 85  15
         checkActual();
 86   
     }
 87   
 }
 88