Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 136   Methods: 5
NCLOC: 86   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ComponentFinderTagHandlerT.java - 100% 100% 100%
coverage
 1   
 package junit.extensions.jfcunit.finder;
 2   
 
 3   
 import javax.swing.BoxLayout;
 4   
 import javax.swing.JButton;
 5   
 import javax.swing.JFrame;
 6   
 
 7   
 import org.w3c.dom.Element;
 8   
 import junit.extensions.jfcunit.AbstractTestCase;
 9   
 import junit.extensions.jfcunit.xml.JFCXMLTestCase;
 10   
 import junit.extensions.xml.XMLException;
 11   
 import junit.extensions.xml.XMLTagResourceBundle;
 12   
 import junit.extensions.xml.elements.AbstractTagHandler;
 13   
 import junit.extensions.xml.elements.ElementFixture;
 14   
 
 15   
 /**
 16   
  * Test case to test the named component tag handler.
 17   
  * @author Kevin Wilson not attributable
 18   
  * @version 1.0
 19   
  */
 20   
 
 21   
 public class ComponentFinderTagHandlerT
 22   
     extends AbstractTestCase {
 23   
 
 24   
     /**
 25   
      * Fixture used to create the test elements and test
 26   
      * cases and test suites.
 27   
      */
 28   
     private ElementFixture m_fixture;
 29   
 
 30   
     /**
 31   
      * Constructor.
 32   
      * @param name of the test case.
 33   
      */
 34  2
     public ComponentFinderTagHandlerT(final String name) {
 35  2
         super(name);
 36   
     }
 37   
 
 38   
     /**
 39   
      * Setup the test.
 40   
      * @throws Exception may be thrown.
 41   
      */
 42  2
     protected void setUp() throws Exception {
 43  2
         super.setUp();
 44  2
         m_fixture = new ElementFixture(this);
 45  2
         m_fixture.setUp();
 46   
     }
 47   
 
 48   
     /**
 49   
      * Tear down the test.
 50   
      * @throws Exception may be thrown.
 51   
      */
 52  2
     protected void tearDown() throws Exception {
 53  2
         m_fixture.tearDown();
 54  2
         m_fixture = null;
 55  2
         super.tearDown();
 56   
     }
 57   
 
 58   
     /**
 59   
      * Test the process element.
 60   
      * @throws XMLException may be thrown.
 61   
      */
 62  1
     public void testProcessElement() throws XMLException {
 63  1
         JFCXMLTestCase tc = m_fixture.getJFCTestCase();
 64  1
         Element e = m_fixture.newElement("find", new String[] {
 65   
                                          "finder", "ComponentFinder",
 66   
                                          "id", "component",
 67   
                                          "index", "1",
 68   
                                          "class", "javax.swing.JButton",
 69   
                                          "operation", "equals",
 70   
                                          "container", "frame"
 71   
         });
 72   
 
 73  1
         JFrame frame = this.createJFrame("TEST");
 74  1
         JButton b1 = new JButton("TEST");
 75  1
         b1.setName("Test");
 76   
 
 77  1
         JButton b2 = new JButton("TEST");
 78  1
         b2.setName("TEST");
 79   
 
 80  1
         frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),
 81   
             BoxLayout.X_AXIS));
 82  1
         frame.getContentPane().add(b1);
 83  1
         frame.getContentPane().add(b2);
 84  1
         tc.addProperty("frame", frame);
 85  1
         packAndShow(frame);
 86   
 
 87  1
         AbstractTagHandler handler = XMLTagResourceBundle.getTagHandler(e, tc,
 88   
             "find");
 89  1
         handler.processElement();
 90  1
         Object o = tc.getProperty("component");
 91  1
         assertSame("ComponentFound should be B2.", b2, o);
 92   
     }
 93   
 
 94   
     /**
 95   
      * Test the processing when a invalid class is used.
 96   
      * @throws XMLException may be thrown.
 97   
      */
 98  1
     public void testProcessInvalidClass() throws XMLException {
 99  1
         JFCXMLTestCase tc = m_fixture.getJFCTestCase();
 100  1
         Element e = m_fixture.newElement("find", new String[] {
 101   
                                          "finder", "ComponentFinder",
 102   
                                          "id", "component",
 103   
                                          "index", "0",
 104   
                                          "class", "javax.swing.JButtonx",
 105   
                                          "operation", "equals",
 106   
                                          "container", "frame"
 107   
         });
 108   
 
 109  1
         JFrame frame = this.createJFrame("TEST");
 110  1
         JButton b1 = new JButton("TEST");
 111  1
         b1.setName("Test");
 112   
 
 113  1
         JButton b2 = new JButton("TEST");
 114  1
         b2.setName("TEST");
 115   
 
 116  1
         frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),
 117   
             BoxLayout.X_AXIS));
 118  1
         frame.getContentPane().add(b1);
 119  1
         frame.getContentPane().add(b2);
 120  1
         tc.addProperty("frame", frame);
 121  1
         packAndShow(frame);
 122   
 
 123  1
         AbstractTagHandler handler = XMLTagResourceBundle.getTagHandler(e, tc,
 124   
             "find");
 125   
 
 126  1
         XMLException xe = null;
 127  1
         try {
 128  1
             handler.processElement();
 129   
         } catch (XMLException xmle) {
 130  1
             xe = xmle;
 131   
         }
 132  1
         assertNotNull("Exception not thrown", xe);
 133   
     }
 134   
 
 135   
 }
 136