Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 177   Methods: 11
NCLOC: 97   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JMenuItemFinderT.java - 100% 100% 100%
coverage
 1   
 package junit.extensions.jfcunit.finder;
 2   
 
 3   
 import junit.extensions.jfcunit.AbstractTestCase;
 4   
 
 5   
 import javax.swing.Icon;
 6   
 import javax.swing.ImageIcon;
 7   
 import javax.swing.JFrame;
 8   
 import javax.swing.JMenuItem;
 9   
 
 10   
 /**
 11   
  * A TestCase to test the methods in the JMenuItemFinder class.
 12   
  *
 13   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 14   
  */
 15   
 public class JMenuItemFinderT extends AbstractTestCase {
 16   
     /**
 17   
      * A private icon used for testing.
 18   
      */
 19   
     private Icon m_validIcon = new ImageIcon(AbstractTestCase.class.getResource("images/duke2.gif"));
 20   
 
 21   
     /**
 22   
      * A private icon used for testing.
 23   
      */
 24   
     private Icon m_validIcon2 = new ImageIcon(AbstractTestCase.class.getResource(
 25   
         "images/duke.gif"));
 26   
 
 27   
     /**
 28   
      * A private icon used for testing.
 29   
      */
 30   
     private Icon m_invalidIcon = new ImageIcon("images/invalid.gif");
 31   
 
 32   
     /**
 33   
      * Constructor.
 34   
      *
 35   
      * @param name Name of the test case.
 36   
      */
 37  10
     public JMenuItemFinderT(final String name) {
 38  10
         super(name);
 39   
     }
 40   
 
 41   
     /**
 42   
      * Test Constructors.
 43   
      */
 44  1
     public void testConstructors() {
 45  1
       new JMenuItemFinder(m_validIcon);
 46  1
       new JMenuItemFinder("test");
 47  1
       new JMenuItemFinder("test", true);
 48  1
       new JMenuItemFinder("test", m_validIcon);
 49  1
       new JMenuItemFinder("test", m_validIcon, true);
 50   
     }
 51   
     /**
 52   
      * Tests the 'testComponent' method for: invalid component.
 53   
      *
 54   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 55   
      */
 56  1
     public void testTestComponentInvalidComponent() throws Exception {
 57  1
         JMenuItemFinder finder = new JMenuItemFinder(null, m_validIcon);
 58  1
         JMenuItem menuItem = new JMenuItem("Some Text", m_validIcon);
 59  1
         JFrame frame = createJFrame(getName());
 60  1
         frame.getContentPane().add(menuItem);
 61  1
         setWindow(frame);
 62  1
         packAndShow(frame);
 63  1
         assertFalse("Finder is not working", finder.testComponent(frame));
 64   
     }
 65   
 
 66   
     /**
 67   
      * Tests the 'testComponent' method for: null label, null icon.
 68   
      *
 69   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 70   
      */
 71  1
     public void testTestComponentNullLabelNullIcon() throws Exception {
 72  1
         JMenuItemFinder finder = new JMenuItemFinder(null, null);
 73  1
         JMenuItem menuItem = new JMenuItem();
 74  1
         JFrame frame = createJFrame(getName());
 75  1
         frame.getContentPane().add(menuItem);
 76  1
         setWindow(frame);
 77  1
         packAndShow(frame);
 78  1
         assertTrue("Finder is not working", finder.testComponent(menuItem));
 79   
     }
 80   
 
 81   
     /**
 82   
      * Tests the 'testComponent' method for: null label, valid icon.
 83   
      *
 84   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 85   
      */
 86  1
     public void testTestComponentNullLabelValidIcon() throws Exception {
 87  1
         JMenuItemFinder finder = new JMenuItemFinder(null, m_validIcon);
 88  1
         JMenuItem menuItem = new JMenuItem("Some Text", m_validIcon);
 89  1
         JFrame frame = createJFrame(getName());
 90  1
         frame.getContentPane().add(menuItem);
 91  1
         setWindow(frame);
 92  1
         packAndShow(frame);
 93  1
         assertTrue("Finder is not working", finder.testComponent(menuItem));
 94   
     }
 95   
 
 96   
     /**
 97   
      * Tests the 'testComponent' method for: invalid label, valid icon.
 98   
      *
 99   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 100   
      */
 101  1
     public void testTestComponentInvalidLabelValidIcon() throws Exception {
 102  1
         JMenuItemFinder finder = new JMenuItemFinder("Invalid Label", m_validIcon);
 103  1
         JMenuItem menuItem = new JMenuItem("Valid Label", m_validIcon);
 104  1
         JFrame frame = createJFrame(getName());
 105  1
         frame.getContentPane().add(menuItem);
 106  1
         setWindow(frame);
 107  1
         packAndShow(frame);
 108  1
         assertFalse("Finder is not working", finder.testComponent(menuItem));
 109   
     }
 110   
 
 111   
     /**
 112   
      * Tests the 'testComponent' method for: valid label, invalid icon.
 113   
      *
 114   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 115   
      */
 116  1
     public void testTestComponentValidLabelInvalidIcon() throws Exception {
 117  1
         JMenuItemFinder finder = new JMenuItemFinder("Valid Label", m_invalidIcon);
 118  1
         JMenuItem menuItem = new JMenuItem("Valid Label", m_validIcon);
 119  1
         JFrame frame = createJFrame(getName());
 120  1
         frame.getContentPane().add(menuItem);
 121  1
         setWindow(frame);
 122  1
         packAndShow(frame);
 123  1
         assertFalse("Finder is not working", finder.testComponent(menuItem));
 124   
     }
 125   
 
 126   
     /**
 127   
      * Tests the 'testComponent' method for: valid label, valid icon.
 128   
      *
 129   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 130   
      */
 131  1
     public void testTestComponentValidLabelValidIconCaseSensitive() throws Exception {
 132  1
         JMenuItemFinder finder = new JMenuItemFinder("Valid Label", m_validIcon);
 133  1
         JMenuItem menuItem = new JMenuItem("Valid Label", m_validIcon);
 134  1
         JFrame frame = createJFrame(getName());
 135  1
         frame.getContentPane().add(menuItem);
 136  1
         setWindow(frame);
 137  1
         packAndShow(frame);
 138  1
         assertTrue("Finder is not working", finder.testComponent(menuItem));
 139   
     }
 140   
 
 141   
     /**
 142   
      * Tests the 'testComponent' method for: valid label, valid icon.
 143   
      *
 144   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 145   
      */
 146  1
     public void testTestComponentValidLabelValidIconCaseInsensitive() throws Exception {
 147  1
         JMenuItemFinder finder = new JMenuItemFinder("vaLId labEL", m_validIcon, true);
 148  1
         JMenuItem menuItem = new JMenuItem("Valid Label", m_validIcon);
 149  1
         JFrame frame = createJFrame(getName());
 150  1
         frame.getContentPane().add(menuItem);
 151  1
         setWindow(frame);
 152  1
         packAndShow(frame);
 153  1
         assertTrue("Finder is not working", finder.testComponent(menuItem));
 154   
     }
 155   
 
 156   
     /**
 157   
      * Test get/setIcon().
 158   
      */
 159  1
     public void testIcon() {
 160  1
         JMenuItemFinder finder = new JMenuItemFinder(m_validIcon);
 161  1
         assertSame(m_validIcon, finder.getIcon());
 162   
 
 163  1
         finder.setIcon(m_validIcon2);
 164  1
         assertSame(m_validIcon2, finder.getIcon());
 165   
     }
 166   
 
 167   
     /**
 168   
      * Test get/setText().
 169   
      */
 170  1
     public void testText() {
 171  1
         JMenuItemFinder finder = new JMenuItemFinder("TEST");
 172  1
         assertEquals("TEST", finder.getText());
 173  1
         finder.setText("ABC");
 174  1
         assertEquals("ABC", finder.getText());
 175   
     }
 176   
 }
 177