Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 188   Methods: 8
NCLOC: 121   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ParentInstanceTagHandlerT.java - 100% 100% 100%
coverage
 1   
 package junit.extensions.xml.elements;
 2   
 
 3   
 import java.util.Vector;
 4   
 
 5   
 import javax.swing.JLabel;
 6   
 import javax.swing.JPanel;
 7   
 
 8   
 import org.w3c.dom.Element;
 9   
 import junit.extensions.xml.IXMLTestCase;
 10   
 import junit.extensions.xml.XMLException;
 11   
 import junit.framework.TestCase;
 12   
 import junit.extensions.xml.XMLTagResourceBundle;
 13   
 
 14   
 /**
 15   
  * <p>Title: Test parent instance tag handler.</p>
 16   
  * <p>Description: </p>
 17   
  * <p>Copyright: Copyright (c) 2003</p>
 18   
  * <p>Company: </p>
 19   
  * @author Kevin Wilson not attributable
 20   
  * @version 1.0
 21   
  */
 22   
 
 23   
 public class ParentInstanceTagHandlerT extends TestCase {
 24   
   /**
 25   
    * tag handler.
 26   
    */
 27   
   private ParentInstanceTagHandler m_parentInstanceTagHandler = null;
 28   
   /**
 29   
    * element fixture.
 30   
    */
 31   
   private ElementFixture m_elementFixture;
 32   
 
 33   
   /**
 34   
    * Set up the test.
 35   
    * @throws Exception may be thrown.
 36   
    */
 37  6
   protected void setUp() throws Exception {
 38  6
     super.setUp();
 39  6
     m_elementFixture = new ElementFixture(this);
 40  6
     m_elementFixture.setUp();
 41   
   }
 42   
 
 43   
   /**
 44   
    * Tear down the test.
 45   
    * @throws Exception may be thrown.
 46   
    */
 47  6
   protected void tearDown() throws Exception {
 48  6
     m_parentInstanceTagHandler = null;
 49  6
     m_elementFixture.tearDown();
 50   
 
 51  6
     m_elementFixture = null;
 52  6
     super.tearDown();
 53   
   }
 54   
 
 55   
   /**
 56   
    * Test processing.
 57   
    * @throws XMLException may be thrown.
 58   
    */
 59  1
   public void testProcessElement() throws XMLException {
 60  1
     JLabel label = new JLabel("abc");
 61  1
     JPanel panel = new JPanel();
 62  1
     panel.add(label);
 63  1
     Element e = m_elementFixture.newElement("getParent", new String[]{
 64   
                                           "id", "parent",
 65   
                                           "refid", "obj",
 66   
                                           "classname", "javax.swing.JPanel"
 67   
     });
 68  1
     IXMLTestCase tc = m_elementFixture.getTestCase();
 69  1
     tc.addProperty("obj", label);
 70  1
     m_parentInstanceTagHandler = new ParentInstanceTagHandler(e, tc);
 71  1
     m_parentInstanceTagHandler.processElement();
 72   
 
 73  1
     Object parent = tc.getProperty("parent");
 74  1
     assertSame(panel, parent);
 75   
   }
 76   
 
 77   
   /**
 78   
    * Test indirect.
 79   
    * @throws XMLException may be thrown.
 80   
    */
 81  1
   public void testIndirect() throws XMLException {
 82  1
     JLabel label = new JLabel("abc");
 83  1
     JPanel panel = new JPanel();
 84  1
     panel.add(label);
 85  1
     Element e = m_elementFixture.newElement("getParent", new String[]{
 86   
                                           "id", "parent",
 87   
                                           "refid", "obj",
 88   
                                           "classname", "javax.swing.JComponent"
 89   
     });
 90  1
     IXMLTestCase tc = m_elementFixture.getTestCase();
 91  1
     tc.addProperty("obj", label);
 92  1
     m_parentInstanceTagHandler = new ParentInstanceTagHandler(e, tc);
 93  1
     m_parentInstanceTagHandler.processElement();
 94   
 
 95  1
     Object parent = tc.getProperty("parent");
 96  1
     assertSame(panel, parent);
 97   
   }
 98   
 
 99   
   /**
 100   
    * Test a invalid class.
 101   
    * @throws XMLException may be thrown.
 102   
    */
 103  1
   public void testInvalidClass() throws XMLException {
 104  1
     JLabel label = new JLabel("abc");
 105  1
     JPanel panel = new JPanel();
 106  1
     panel.add(label);
 107  1
     Element element = m_elementFixture.newElement("getParent", new String[]{
 108   
                                           "id", "parent",
 109   
                                           "refid", "obj",
 110   
                                           "classname", "javax.swing.JBogus"
 111   
     });
 112  1
     IXMLTestCase tc = m_elementFixture.getTestCase();
 113  1
     tc.addProperty("obj", label);
 114  1
     m_parentInstanceTagHandler = new ParentInstanceTagHandler(element, tc);
 115   
 
 116  1
     Exception ex = null;
 117  1
     try {
 118  1
       m_parentInstanceTagHandler.processElement();
 119   
     } catch (Exception e) {
 120  1
       ex = e;
 121   
     }
 122   
 
 123  1
     assertNotNull("Exception expected", ex);
 124   
   }
 125   
 
 126   
   /**
 127   
    * Test not found.
 128   
    * @throws XMLException may be thrown.
 129   
    */
 130  1
   public void testNotFound() throws XMLException {
 131  1
     JLabel label = new JLabel("abc");
 132  1
     JPanel panel = new JPanel();
 133  1
     panel.add(label);
 134  1
     Element element = m_elementFixture.newElement("getParent", new String[]{
 135   
                                           "id", "parent",
 136   
                                           "refid", "obj",
 137   
                                           "classname", "javax.swing.JList"
 138   
     });
 139  1
     IXMLTestCase tc = m_elementFixture.getTestCase();
 140  1
     tc.addProperty("obj", label);
 141  1
     m_parentInstanceTagHandler = new ParentInstanceTagHandler(element, tc);
 142   
 
 143  1
     m_parentInstanceTagHandler.processElement();
 144  1
     Object parent = tc.getProperty("parent");
 145  1
     assertNull("Parent should not be found", parent);
 146   
   }
 147   
 
 148   
   /**
 149   
    * test invalid component.
 150   
    * @throws XMLException may be thrown.
 151   
    */
 152  1
   public void testInvalidComp() throws XMLException {
 153  1
     Vector v = new Vector();
 154  1
     Element element = m_elementFixture.newElement("getParent", new String[]{
 155   
                                           "id", "parent",
 156   
                                           "refid", "obj",
 157   
                                           "classname", "javax.swing.JButton"
 158   
     });
 159  1
     IXMLTestCase tc = m_elementFixture.getTestCase();
 160  1
     tc.addProperty("obj", v);
 161  1
     m_parentInstanceTagHandler = new ParentInstanceTagHandler(element, tc);
 162   
 
 163  1
     Exception ex = null;
 164  1
     try {
 165  1
       m_parentInstanceTagHandler.processElement();
 166   
     } catch (Exception e) {
 167  1
       ex = e;
 168   
     }
 169  1
     assertNotNull("Exception expected:", ex);
 170   
   }
 171   
 
 172   
   /**
 173   
    * Test with the Tag lookup.
 174   
    */
 175  1
   public void testLookup() {
 176  1
     Element element = m_elementFixture.newElement("getParent", new String[] {
 177   
                                                   "id", "parent",
 178   
                                                   "refid", "obj",
 179   
                                                   "classname",
 180   
                                                   "javax.swing.JButton"
 181   
     });
 182  1
     IXMLTestCase tc = m_elementFixture.getTestCase();
 183  1
     Object o = XMLTagResourceBundle.getTagHandler(element, tc, "getparent");
 184  1
     assertNotNull(o);
 185   
   }
 186   
 
 187   
 }
 188