Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 233   Methods: 9
NCLOC: 151   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AssertHasFocusTagHandlerT.java 100% 100% 100% 100%
coverage
 1   
 package junit.extensions.xml.elements;
 2   
 
 3   
 import java.util.Vector;
 4   
 
 5   
 import java.awt.Component;
 6   
 import javax.swing.BoxLayout;
 7   
 import javax.swing.JButton;
 8   
 import javax.swing.JFrame;
 9   
 import javax.swing.JLabel;
 10   
 
 11   
 import org.w3c.dom.Element;
 12   
 import junit.extensions.xml.IXMLTestCase;
 13   
 import junit.extensions.xml.XMLException;
 14   
 import junit.framework.TestCase;
 15   
 import junit.extensions.xml.XMLTagResourceBundle;
 16   
 
 17   
 /**
 18   
  * <p>Title: Test AsertHasFocusTagHandler.</p>
 19   
  * <p>Copyright: Copyright (c) 2003</p>
 20   
  * <p>Company: JFCUnit OpenSource Project</p>
 21   
  * @author Kevin Wilson
 22   
  * @version 1.0
 23   
  */
 24   
 public class AssertHasFocusTagHandlerT
 25   
     extends TestCase {
 26   
 
 27   
   /**
 28   
    * Test tag handler.
 29   
    */
 30   
   private AssertHasFocusTagHandler m_tagHandler = null;
 31   
 
 32   
   /**
 33   
    * Test fixture.
 34   
    */
 35   
   private ElementFixture m_fixture;
 36   
 
 37   
   /**
 38   
    * Test frame.
 39   
    */
 40   
   private JFrame m_frame = null;
 41   
 
 42   
   /**
 43   
    * Setup the test.
 44   
    * @throws Exception may be thrown.
 45   
    */
 46  6
   protected void setUp() throws Exception {
 47  6
     super.setUp();
 48  6
     m_fixture = new ElementFixture(this);
 49   
 
 50  6
     m_fixture.setUp();
 51   
   }
 52   
 
 53   
   /**
 54   
    * Tear down the test.
 55   
    * @throws Exception may be thrown.
 56   
    */
 57  6
   protected void tearDown() throws Exception {
 58  6
     if (m_frame != null) {
 59  4
       m_frame.setVisible(false);
 60  4
       m_frame.dispose();
 61  4
       m_frame = null;
 62   
     }
 63  6
     m_tagHandler = null;
 64  6
     m_fixture.tearDown();
 65   
 
 66  6
     m_fixture = null;
 67  6
     super.tearDown();
 68   
   }
 69   
 
 70   
   /**
 71   
    * Test Process element.
 72   
    * @throws XMLException may be thrown.
 73   
    */
 74  1
   public void testProcessElement() throws XMLException {
 75   
 
 76  1
     Element hasFocus = m_fixture.newElement("asserthasfocus",
 77   
                                             new String[] {
 78   
                                             "refid", "test"
 79   
     });
 80  1
     IXMLTestCase tc = m_fixture.getTestCase();
 81  1
     Component comp = getComponent(0);
 82  1
     tc.addProperty("test", comp);
 83  1
     m_tagHandler = new AssertHasFocusTagHandler(hasFocus, tc);
 84   
 
 85  1
     Throwable ex = null;
 86  1
     try {
 87  1
       m_tagHandler.processElement();
 88   
     } catch (Throwable e) {
 89  1
       ex = e;
 90   
     }
 91  1
     assertNotNull("Throwable expected", ex);
 92   
   }
 93   
 
 94   
   /**
 95   
    * Test process element without focus.
 96   
    * @throws XMLException may be thrown.
 97   
    */
 98  1
   public void testProcessElement1() throws XMLException {
 99   
 
 100  1
     Element hasFocus = m_fixture.newElement("asserthasfocus",
 101   
                                             new String[] {
 102   
                                             "refid", "test"
 103   
     });
 104  1
     IXMLTestCase tc = m_fixture.getTestCase();
 105  1
     Component comp = getComponent(1);
 106  1
     tc.addProperty("test", comp);
 107  1
     m_tagHandler = new AssertHasFocusTagHandler(hasFocus, tc);
 108   
 
 109  1
     Throwable ex = null;
 110  1
     try {
 111  1
       m_tagHandler.processElement();
 112   
     } catch (Throwable e) {
 113  1
       ex = e;
 114   
     }
 115  1
     assertNotNull("Throwable expected", ex);
 116   
   }
 117   
 
 118   
   /**
 119   
    * Test process element without focus.
 120   
    * @throws XMLException may be thrown.
 121   
    */
 122  1
   public void testProcessElement2() throws XMLException {
 123   
 
 124  1
     Element hasFocus = m_fixture.newElement("asserthasfocus",
 125   
                                             new String[] {
 126   
                                             "refid", "test"
 127   
     });
 128  1
     IXMLTestCase tc = m_fixture.getTestCase();
 129  1
     Component comp = getComponent(2);
 130  1
     tc.addProperty("test", comp);
 131  1
     m_tagHandler = new AssertHasFocusTagHandler(hasFocus, tc);
 132  1
     m_tagHandler.processElement();
 133   
   }
 134   
 
 135   
   /**
 136   
    * Test process element.
 137   
    * @throws XMLException may be thrown.
 138   
    */
 139  1
   public void testProcessElement3() throws XMLException {
 140   
 
 141  1
     Element hasFocus = m_fixture.newElement("asserthasfocus",
 142   
                                             new String[] {
 143   
                                             "refid", "test"
 144   
     });
 145  1
     IXMLTestCase tc = m_fixture.getTestCase();
 146  1
     Component comp = getComponent(3);
 147  1
     tc.addProperty("test", comp);
 148  1
     m_tagHandler = new AssertHasFocusTagHandler(hasFocus, tc);
 149   
 
 150  1
     Throwable ex = null;
 151  1
     try {
 152  1
       m_tagHandler.processElement();
 153   
     } catch (Throwable e) {
 154  1
       ex = e;
 155   
     }
 156  1
     assertNotNull("Throwable expected", ex);
 157   
   }
 158   
 
 159   
   /**
 160   
    * Test invalid component.
 161   
    * @throws XMLException may be thrown.
 162   
    */
 163  1
   public void testProcessNonComponent() throws XMLException {
 164   
 
 165  1
     Element hasFocus = m_fixture.newElement("asserthasfocus",
 166   
                                             new String[] {
 167   
                                             "refid", "test"
 168   
     });
 169  1
     IXMLTestCase tc = m_fixture.getTestCase();
 170  1
     Vector v = new Vector();
 171  1
     tc.addProperty("test", v);
 172  1
     m_tagHandler = new AssertHasFocusTagHandler(hasFocus, tc);
 173   
 
 174  1
     Throwable ex = null;
 175  1
     try {
 176  1
       m_tagHandler.processElement();
 177   
     } catch (Throwable e) {
 178  1
       ex = e;
 179   
     }
 180  1
     assertNotNull("Throwable expected", ex);
 181   
   }
 182   
 
 183   
   /**
 184   
    * Test the Tag lookup.
 185   
    */
 186  1
   public void testLookup() {
 187  1
     Element hasFocus = m_fixture.newElement("asserthasfocus",
 188   
                                             new String[] {
 189   
                                             "refid", "test"
 190   
     });
 191  1
     IXMLTestCase tc = m_fixture.getTestCase();
 192  1
     Object o = XMLTagResourceBundle.getTagHandler(hasFocus, tc, "asserthasfocus");
 193  1
     assertNotNull(o);
 194   
   }
 195   
 
 196   
   /**
 197   
    * Create the appropriate infrastructure return the component
 198   
    * requested.
 199   
    * @param comp int component to gain focus. 0 - frame, 1 - label, 2 - button, 3 - second button.
 200   
    * @return Component Frame, Label, or Button.
 201   
    */
 202  4
   private Component getComponent(final int comp) {
 203  4
     int item = comp % 4;
 204  4
     m_frame = new JFrame();
 205  4
     m_frame.getContentPane().setLayout(new BoxLayout(m_frame.getContentPane(),
 206   
         BoxLayout.Y_AXIS));
 207  4
     JLabel label = new JLabel("TEST");
 208  4
     JButton button1 = new JButton("B1");
 209  4
     JButton button2 = new JButton("B2");
 210  4
     m_frame.getContentPane().add(label);
 211  4
     m_frame.getContentPane().add(button1);
 212  4
     m_frame.getContentPane().add(button2);
 213  4
     m_frame.pack();
 214  4
     m_frame.show();
 215  4
     button1.requestFocus();
 216  4
     try {
 217  4
       Thread.sleep(1000);
 218   
     } catch (InterruptedException ex) {
 219   
     }
 220  4
     switch (item) {
 221  1
       case 1:
 222  1
         return label;
 223  1
       case 2:
 224  1
         return button1;
 225  1
       case 3:
 226  1
         return button2;
 227  1
       default:
 228  1
         return m_frame;
 229   
     }
 230   
   }
 231   
 
 232   
 }
 233