Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 333   Methods: 14
NCLOC: 211   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JComboBoxMouseEventDataT.java 100% 100% 100% 100%
coverage
 1   
 package junit.extensions.jfcunit.eventdata;
 2   
 
 3   
 import java.awt.Component;
 4   
 import java.awt.Dimension;
 5   
 import java.awt.Point;
 6   
 import javax.swing.JComboBox;
 7   
 import javax.swing.JScrollPane;
 8   
 import javax.swing.LookAndFeel;
 9   
 import javax.swing.UIManager;
 10   
 import javax.swing.UIManager.LookAndFeelInfo;
 11   
 import javax.swing.UnsupportedLookAndFeelException;
 12   
 
 13   
 import junit.extensions.jfcunit.JFCTestCase;
 14   
 import junit.extensions.jfcunit.JFCTestHelper;
 15   
 import junit.extensions.jfcunit.tools.JFCUtilities;
 16   
 
 17   
 /**
 18   
  * Data container class that holds all the data necessary for jfcUnit to fire mouse events.
 19   
  * This class is specific to events on a JComboBox.
 20   
  *
 21   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 22   
  */
 23   
 public class JComboBoxMouseEventDataT
 24   
     extends MouseEventDataBC {
 25   
 
 26   
   /**
 27   
    * Event data to be validated.
 28   
    */
 29   
   private JComboBoxMouseEventData m_event1 = null;
 30   
 
 31   
   /**
 32   
    * Second Event data to be validated.
 33   
    */
 34   
   private JComboBoxMouseEventData m_event2 = null;
 35   
 
 36   
   /**
 37   
    * A combo box for the test cases.
 38   
    */
 39   
   private static final JComboBox CB1 = new JComboBox();
 40   
 
 41   
   /**
 42   
    * A second combo box for the test cases.
 43   
    */
 44   
   private static final JComboBox CB2 = new JComboBox();
 45   
 
 46   
   /**
 47   
 `   * Default constructor that accepts a String.
 48   
    *
 49   
    * @param   name      The name of the test method to execute.
 50   
    */
 51  10
   public JComboBoxMouseEventDataT(final String name) {
 52  10
     super(name);
 53   
   }
 54   
 
 55   
   /**
 56   
    * Overridden method that is used to remove the test fixtures.
 57   
    *
 58   
    * @exception  Exception   An instance of java.lang.Exception can be thrown
 59   
    */
 60  10
   protected void tearDown() throws Exception {
 61  10
     super.tearDown();
 62  10
     m_event1 = null;
 63  10
     m_event2 = null;
 64   
   }
 65   
 
 66   
   /**
 67   
    * Validate the construction of the event data.
 68   
    *
 69   
    * @param event Event to be validated against the
 70   
    *   following values.
 71   
    * @param tc    TestCase value.
 72   
    * @param cb    ComboBox value.
 73   
    * @param index ComboBox index value.
 74   
    * @param clicks Number of clicks.
 75   
    * @param modifiers Modifiers
 76   
    * @param popup Popup flag.
 77   
    * @param sleepTime Sleep time.
 78   
    * @param position Position
 79   
    * @param ref Reference point.
 80   
    */
 81  12
   protected void validateEvent(
 82   
       final JComboBoxMouseEventData event,
 83   
       final JFCTestCase tc,
 84   
       final JComboBox cb,
 85   
       final int index,
 86   
       final int clicks,
 87   
       final int modifiers,
 88   
       final boolean popup,
 89   
       final long sleepTime,
 90   
       final int position,
 91   
       final Point ref) {
 92   
 
 93  12
     super.validateEvent(event, tc, (Component) cb, clicks, modifiers, popup,
 94   
                         sleepTime, position, ref);
 95   
 
 96  12
     assertEquals("Index:", index, event.getElementIndex());
 97  12
     assertSameOrNull("Source:", cb, event.getSource());
 98   
   }
 99   
 
 100   
   /**
 101   
    * Test the constructor.
 102   
    */
 103  1
   public void testJComboBoxMouseEventData1() {
 104  1
     m_event1 = new JComboBoxMouseEventData();
 105  1
     assertEquals("Should be invalid", false, m_event1.isValid());
 106  1
     assertEquals("Prepare result:", false, m_event1.prepareComponent());
 107   
   }
 108   
 
 109   
   /**
 110   
    * Test the constructor.
 111   
    */
 112  1
   public void testJComboBoxMouseEventData2() {
 113  1
     m_event1 = new JComboBoxMouseEventData(this, CB1, 1, 1);
 114  1
     validateEvent(m_event1, this, CB1, 1, 1, DEFAULT_MOUSE_MODIFIERS,
 115   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 116   
 
 117  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 2, 2);
 118  1
     validateEvent(m_event2, this, CB2, 2, 2, DEFAULT_MOUSE_MODIFIERS,
 119   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 120   
   }
 121   
 
 122   
   /**
 123   
    * Test the constructor.
 124   
    */
 125  1
   public void testJComboBoxMouseEventData3() {
 126  1
     m_event1 = new JComboBoxMouseEventData(this, CB1, 1, 1, 500);
 127  1
     validateEvent(m_event1, this, CB1, 1, 1, DEFAULT_MOUSE_MODIFIERS,
 128   
                   DEFAULT_ISPOPUPTRIGGER, 500, DEFAULT_POSITION, null);
 129   
 
 130  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 3, 2, 1500);
 131  1
     validateEvent(m_event2, this, CB2, 3, 2, DEFAULT_MOUSE_MODIFIERS,
 132   
                   DEFAULT_ISPOPUPTRIGGER, 1500, DEFAULT_POSITION, null);
 133   
   }
 134   
 
 135   
   /**
 136   
    * Test the constructor.
 137   
    */
 138  1
   public void testJComboBoxMouseEventData4() {
 139  1
     m_event1 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 140   
                                            500);
 141  1
     validateEvent(m_event1, this, CB1, 1, 1, MODIFIERS1, true, 500,
 142   
                   DEFAULT_POSITION, null);
 143   
 
 144  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 2, 2, MODIFIERS2, false,
 145   
                                            1500);
 146  1
     validateEvent(m_event2, this, CB2, 2, 2, MODIFIERS2, false, 1500,
 147   
                   DEFAULT_POSITION, null);
 148   
   }
 149   
 
 150   
   /**
 151   
    * Test the constructor.
 152   
    */
 153  1
   public void testJComboBoxMouseEventData5() {
 154  1
     m_event1 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 155   
                                            500, P1);
 156  1
     validateEvent(m_event1, this, CB1, 1, 1, MODIFIERS1, true, 500, CUSTOM, P1);
 157   
 
 158  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 2, 2, MODIFIERS2, false,
 159   
                                            1500, P2);
 160  1
     validateEvent(m_event2, this, CB2, 2, 2, MODIFIERS2, false, 1500, CUSTOM,
 161   
                   P2);
 162   
   }
 163   
 
 164   
   /**
 165   
    * Test the constructor.
 166   
    */
 167  1
   public void testJComboBoxMouseEventData6() {
 168  1
     m_event1 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 169   
                                            500, WEST);
 170  1
     validateEvent(m_event1, this, CB1, 1, 1, MODIFIERS1, true, 500, WEST, null);
 171   
 
 172  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 2, 2, MODIFIERS2, false,
 173   
                                            1500, NORTH_WEST);
 174  1
     validateEvent(m_event2, this, CB2, 2, 2, MODIFIERS2, false, 1500,
 175   
                   NORTH_WEST, null);
 176   
   }
 177   
 
 178   
   /**
 179   
    * Test the constructor.
 180   
    */
 181  1
   public void testJComboBoxMouseEventData7() {
 182  1
     m_event1 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 183   
                                            500, CUSTOM, P1);
 184  1
     validateEvent(m_event1, this, CB1, 1, 1, MODIFIERS1, true, 500, CUSTOM, P1);
 185   
 
 186  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 2, 2, MODIFIERS2, false,
 187   
                                            1500, PERCENT, P2);
 188  1
     validateEvent(m_event2, this, CB2, 2, 2, MODIFIERS2, false, 1500, PERCENT,
 189   
                   P2);
 190   
   }
 191   
 
 192   
   /**
 193   
    * Test the equals.
 194   
    */
 195  1
   public void testEquals() {
 196  1
     m_event1 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 197   
                                            500, CUSTOM, P1);
 198  1
     m_event2 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 199   
                                            500, CUSTOM, P1);
 200  1
     assertTrue("Not equals:", m_event1.equals(m_event2));
 201  1
     assertTrue("Null equals:", !m_event1.equals(null));
 202  1
     assertTrue("Invalid class:", !m_event1.equals(""));
 203   
 
 204  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 1, 1, MODIFIERS1, true,
 205   
                                            500, CUSTOM, P1);
 206  1
     assertTrue("Equals but Component different:", !m_event1.equals(m_event2));
 207   
 
 208  1
     m_event2 = new JComboBoxMouseEventData(this, CB1, 2, 1, MODIFIERS1, true,
 209   
                                            500, CUSTOM, P1);
 210  1
     assertTrue("Equals but Index different:", !m_event1.equals(m_event2));
 211  1
     m_event2 = new JComboBoxMouseEventData(this, CB1, 1, 2, MODIFIERS1, true,
 212   
                                            500, CUSTOM, P1);
 213  1
     assertTrue("Equals but Clicks different:", !m_event1.equals(m_event2));
 214  1
     m_event2 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS2, true,
 215   
                                            500, CUSTOM, P1);
 216  1
     assertTrue("Equals but Modifiers different:", !m_event1.equals(m_event2));
 217  1
     m_event2 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, false,
 218   
                                            500, CUSTOM, P1);
 219  1
     assertTrue("Equals but Popup different:", !m_event1.equals(m_event2));
 220  1
     m_event2 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 221   
                                            500, PERCENT, P1);
 222  1
     assertTrue("Equals but Position different:", !m_event1.equals(m_event2));
 223  1
     m_event2 = new JComboBoxMouseEventData(this, CB1, 1, 1, MODIFIERS1, true,
 224   
                                            500, CUSTOM, P2);
 225  1
     assertTrue("Equals but Reference different:", !m_event1.equals(m_event2));
 226  1
     m_event2 = new JComboBoxMouseEventData(this, CB2, 2, 2, MODIFIERS2, false,
 227   
                                            500, PERCENT, P2);
 228  1
     assertTrue("Equals but All different:", !m_event1.equals(m_event2));
 229   
   }
 230   
 
 231   
   /**
 232   
    * This method is used to test that when the JComboBox item's width is much greater
 233   
    * than the view port, the click point is recalculated correctly.
 234   
    */
 235  1
   public void testPrepareComponentWithCenterPointOutsideVisibleArea() {
 236  1
     try {
 237  1
       setHelper(new JFCTestHelper());
 238   
     } catch (Exception e) {
 239   
     }
 240  1
     String longString = "with a very long, long line - hope that this is"
 241   
        + " enough. Is this enough? No? Ok, lets go some more - is this"
 242   
        + " ok? Finally!";
 243  1
     setWindow(createJFrame(getName()));
 244   
     // for this test, the frame should not contain the full width of the JList items
 245  1
     getFrame().setSize(35, 100);
 246   
 
 247  1
     Object[] items = new Object[] {
 248   
         "Items-0" + longString,
 249   
         "Items-1" + longString,
 250   
         "Items-2" + longString,
 251   
         "Items-3" + longString};
 252  1
     JComboBox combo = new JComboBox(items);
 253   
 
 254  1
     JScrollPane scrollPane = new JScrollPane(JScrollPane.
 255   
                                              VERTICAL_SCROLLBAR_AS_NEEDED,
 256   
                                              JScrollPane.
 257   
                                              HORIZONTAL_SCROLLBAR_AS_NEEDED);
 258  1
     scrollPane.setPreferredSize(new Dimension(20, 50));
 259  1
     scrollPane.setViewportView(combo);
 260   
 
 261  1
     getFrame().getContentPane().add(scrollPane);
 262   
     // do not use the packAndShow() method - since we want the viewport to be smaller than the combo width...
 263  1
     JFCUtilities.center(getFrame());
 264  1
     getFrame().setVisible(true);
 265   
 
 266  1
     for (int index = 0; index < items.length; index++) {
 267  4
       getHelper().enterClickAndLeave(new JComboBoxMouseEventData(this, combo,
 268   
           index, 1));
 269  4
       sleep(getSleepTimer());
 270  4
       pauseAWT();
 271  4
       assertEquals("Selected item is wrong", "Items-" + index + longString,
 272   
                    combo.getSelectedItem());
 273  4
       resumeAWT();
 274   
     }
 275   
   }
 276   
 
 277   
   /**
 278   
    * This method is used to test that when the JComboBox item's width is much greater
 279   
    * than the view port, the click point is recalculated correctly.
 280   
    */
 281  1
   public void testEditableComboBox() {
 282  1
     try {
 283  1
       setHelper(new JFCTestHelper());
 284   
     } catch (Exception e) {
 285   
     }
 286  1
     LookAndFeelInfo[] looks = javax.swing.UIManager.getInstalledLookAndFeels();
 287  1
     setLookAndFeel(looks[0]);
 288   
 
 289  1
     setWindow(createJFrame(getName()));
 290   
     // for this test, the frame should not
 291   
     // contain the full width of the JList items
 292   
 
 293  1
     Object[] items = new Object[] {
 294   
         "Items-0",
 295   
         "Items-1",
 296   
         "Items-2",
 297   
         "Items-3"
 298   
     };
 299  1
     JComboBox combo = new JComboBox(items);
 300  1
     combo.setEditable(true);
 301  1
     getFrame().getContentPane().add(combo);
 302   
     // do not use the packAndShow() method - since we want the viewport to be smaller than the combo width...
 303  1
     getFrame().pack();
 304  1
     JFCUtilities.center(getFrame());
 305  1
     getFrame().setVisible(true);
 306  1
     for (int index = 0; index < items.length; index++) {
 307  4
       getHelper().enterClickAndLeave(new JComboBoxMouseEventData(this, combo,
 308   
           index, 1));
 309  4
       sleep(getSleepTimer());
 310  4
       pauseAWT();
 311  4
       assertEquals("Selected item is wrong", "Items-" + index,
 312   
                    combo.getSelectedItem());
 313  4
       resumeAWT();
 314   
     }
 315   
   }
 316   
 
 317   
   /**
 318   
    * Set the look and feel.
 319   
    * @param looks LookAndFeelInfo to be used.
 320   
    */
 321  1
   private void setLookAndFeel(final LookAndFeelInfo looks) {
 322  1
       try {
 323  1
           Class cls = Class.forName(looks.getClassName());
 324  1
           LookAndFeel laf = (LookAndFeel) cls.newInstance();
 325  1
           UIManager.setLookAndFeel(laf);
 326   
       } catch (UnsupportedLookAndFeelException ex1) {
 327   
       } catch (IllegalAccessException ex1) {
 328   
       } catch (InstantiationException ex1) {
 329   
       } catch (ClassNotFoundException ex1) {
 330   
       }
 331   
   }
 332   
 }
 333