Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 160   Methods: 7
NCLOC: 96   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LabeledComponentFinderT.java - 100% 100% 100%
coverage
 1   
 package junit.extensions.jfcunit.finder;
 2   
 
 3   
 import java.awt.Component;
 4   
 import java.awt.Container;
 5   
 import javax.swing.BoxLayout;
 6   
 import javax.swing.JFrame;
 7   
 import javax.swing.JLabel;
 8   
 import javax.swing.JTextField;
 9   
 
 10   
 import junit.extensions.jfcunit.AbstractTestCase;
 11   
 import javax.swing.Icon;
 12   
 import javax.swing.UIManager;
 13   
 import javax.swing.ImageIcon;
 14   
 
 15   
 /**
 16   
  * Test LabeledComponentFinder.
 17   
  * @author Kevin Wilson not attributable
 18   
  * @version 1.0
 19   
  */
 20   
 public class LabeledComponentFinderT
 21   
     extends AbstractTestCase {
 22   
 
 23   
 
 24   
     /**
 25   
         * A private icon used for testing.
 26   
         */
 27   
        private Icon m_validIcon = new ImageIcon(AbstractTestCase.class.getResource(
 28   
            "images/duke2.gif"));
 29   
 
 30   
        /**
 31   
         * A private icon used for testing.
 32   
         */
 33   
        private Icon m_validIcon2 = new ImageIcon(AbstractTestCase.class.getResource(
 34   
            "images/duke.gif"));
 35   
 
 36   
        /**
 37   
         * A private icon used for testing, this one is smaller.
 38   
         */
 39   
        private Icon m_validIcon3 = UIManager.getIcon("FileView.floppyDriveIcon");
 40   
 
 41   
        /**
 42   
         * A private icon used for testing.
 43   
         */
 44   
        private Icon m_invalidIcon = new ImageIcon("images/invalid.gif");
 45   
 
 46   
     /**
 47   
      * Constructor.
 48   
      * @param name Name of the test case.
 49   
      */
 50  4
     public LabeledComponentFinderT(final String name) {
 51  4
         super(name);
 52   
     }
 53   
 
 54   
     /**
 55   
      * Setup the test.
 56   
      * @throws Exception may be thrown.
 57   
      */
 58  4
     protected void setUp() throws Exception {
 59  4
         super.setUp();
 60   
     }
 61   
 
 62   
     /**
 63   
      * Teardown the test.
 64   
      * @throws Exception may be thrown.
 65   
      */
 66  4
     protected void tearDown() throws Exception {
 67  4
         super.tearDown();
 68   
     }
 69   
 
 70   
     /**
 71   
      * Test the find() method.
 72   
      */
 73  1
     public void testFind() {
 74  1
         JFrame frame = this.createJFrame(getName());
 75  1
         setWindow(frame);
 76  1
         JLabel l1 = new JLabel("test");
 77  1
         l1.setName("l1");
 78  1
         JTextField t1 = new JTextField();
 79  1
         t1.setName("T1");
 80  1
         l1.setLabelFor(t1);
 81  1
         Container c = frame.getContentPane();
 82  1
         c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
 83  1
         c.add(l1);
 84  1
         c.add(t1);
 85  1
         this.packAndShow(frame);
 86   
 
 87  1
         Finder f = new LabeledComponentFinder("test", false);
 88  1
         Component comp = f.find(frame, 0);
 89  1
         assertSame(t1, comp);
 90   
     }
 91   
 
 92   
     /**
 93   
      * Test the find() with no label.
 94   
      */
 95  1
     public void testFindWithNullLabel() {
 96  1
         JFrame frame = this.createJFrame(getName());
 97  1
         setWindow(frame);
 98  1
         JLabel l1 = new JLabel();
 99  1
         l1.setName("l1");
 100  1
         JTextField t1 = new JTextField();
 101  1
         t1.setName("T1");
 102  1
         l1.setLabelFor(t1);
 103  1
         Container c = frame.getContentPane();
 104  1
         c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
 105  1
         c.add(l1);
 106  1
         c.add(t1);
 107  1
         this.packAndShow(frame);
 108   
 
 109  1
         Finder f = new LabeledComponentFinder("", false);
 110  1
         Component comp = f.find(frame, 0);
 111  1
         assertSame(t1, comp);
 112   
     }
 113   
 
 114   
 
 115   
     /**
 116   
      * Test the find() with no label.
 117   
      */
 118  1
     public void testFindWithNullInHierarchy() {
 119  1
         JFrame frame = this.createJFrame(getName());
 120  1
         setWindow(frame);
 121  1
         JLabel l1 = new JLabel();
 122  1
         l1.setName("l1");
 123  1
         JTextField t1 = new JTextField();
 124  1
         t1.setName("T1");
 125  1
         Container c = frame.getContentPane();
 126  1
         c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
 127  1
         c.add(l1);
 128  1
         c.add(t1);
 129  1
         this.packAndShow(frame);
 130   
 
 131  1
         Finder f = new LabeledComponentFinder("", false);
 132  1
         Component comp = f.find(frame, 0);
 133  1
         assertNull("Null expected when setLabelFor is not set", comp);
 134   
     }
 135   
 
 136   
 
 137   
     /**
 138   
      * Test the find() with no label.
 139   
      */
 140  1
     public void testFindWithIcon() {
 141  1
         JFrame frame = this.createJFrame(getName());
 142  1
         setWindow(frame);
 143  1
         JLabel l1 = new JLabel(this.m_validIcon);
 144  1
         l1.setName("l1");
 145  1
         JTextField t1 = new JTextField();
 146  1
         t1.setName("T1");
 147  1
         l1.setLabelFor(t1);
 148  1
         Container c = frame.getContentPane();
 149  1
         c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
 150  1
         c.add(l1);
 151  1
         c.add(t1);
 152  1
         this.packAndShow(frame);
 153   
 
 154  1
         Finder f = new LabeledComponentFinder(null, false);
 155  1
         Component comp = f.find(frame, 0);
 156  1
         assertSame(t1, comp);
 157   
     }
 158   
 
 159   
 }
 160