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