Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 412   Methods: 19
NCLOC: 262   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JTabbedPaneMouseEventDataT.java 100% 100% 100% 100%
coverage
 1   
 package junit.extensions.jfcunit.eventdata;
 2   
 
 3   
 import junit.extensions.jfcunit.JFCTestCase;
 4   
 import junit.extensions.jfcunit.JFCTestHelper;
 5   
 
 6   
 import java.awt.Dimension;
 7   
 import java.awt.GridBagLayout;
 8   
 import java.awt.Point;
 9   
 import java.awt.event.MouseAdapter;
 10   
 import java.awt.event.MouseEvent;
 11   
 import java.awt.event.MouseListener;
 12   
 import java.util.Vector;
 13   
 
 14   
 import javax.swing.JButton;
 15   
 import javax.swing.JPanel;
 16   
 import javax.swing.JScrollPane;
 17   
 import javax.swing.JTabbedPane;
 18   
 
 19   
 import junit.extensions.jfcunit.tools.JFCUtilities;
 20   
 
 21   
 /**
 22   
  * Data container class that holds all the data necessary for jfcUnit to fire mouse events.
 23   
  * This class is specific to events on a JTabbedPane.
 24   
  *
 25   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 26   
  */
 27   
 public class JTabbedPaneMouseEventDataT
 28   
     extends MouseEventDataBC {
 29   
   /**
 30   
    * Event data to be validated.
 31   
    */
 32   
   private JTabbedPaneMouseEventData m_event1 = null;
 33   
 
 34   
   /**
 35   
    * Second Event data to be validated.
 36   
    */
 37   
   private JTabbedPaneMouseEventData m_event2 = null;
 38   
 
 39   
   /**
 40   
    * Component to be tested.
 41   
    */
 42   
   private static final JTabbedPane TB1 = new JTabbedPane();
 43   
 
 44   
   /**
 45   
    * Second component to be tested.
 46   
    */
 47   
   private static final JTabbedPane TB2 = new JTabbedPane();
 48   
 
 49   
   /**
 50   
    * Title to be tested.
 51   
    */
 52   
   private static final String TITLE1 = "ABC";
 53   
 
 54   
   /**
 55   
    * Second title to be tested.
 56   
    */
 57   
   private static final String TITLE2 = "DEF";
 58   
 
 59   
   /**
 60   
    * Default title.
 61   
    */
 62   
   private static final String DEFAULT_TITLE = "";
 63   
 
 64   
   /**
 65   
    * Default constructor that accepts a String.
 66   
    *
 67   
    * @param   name      The name of the test method to execute.
 68   
    */
 69  15
   public JTabbedPaneMouseEventDataT(final String name) {
 70  15
     super(name);
 71   
   }
 72   
 
 73   
   /**
 74   
    * Overridden method that is used to remove the test fixtures.
 75   
    *
 76   
    * @exception  Exception   An instance of java.lang.Exception can be thrown
 77   
    */
 78  15
   protected void tearDown() throws Exception {
 79  15
     super.tearDown();
 80  15
     m_event1 = null;
 81  15
     m_event2 = null;
 82   
   }
 83   
 
 84   
   /**
 85   
    * Validate the parameters of the event match the values
 86   
    * given.
 87   
    *
 88   
    * @param event Event to be tested.
 89   
    * @param tc TestCase
 90   
    * @param tp component
 91   
    * @param index Index of tab.
 92   
    * @param title Title of tab.
 93   
    * @param clicks mouse clicks.
 94   
    * @param modifiers Modifiers to be used.
 95   
    * @param popup Popup
 96   
    * @param sleepTime sleep duration.
 97   
    * @param position locatio of mouse.
 98   
    * @param ref Reference location.
 99   
    */
 100  24
   protected void validateEvent(
 101   
       final JTabbedPaneMouseEventData event,
 102   
       final JFCTestCase tc,
 103   
       final JTabbedPane tp,
 104   
       final int index,
 105   
       final String title,
 106   
       final int clicks,
 107   
       final int modifiers,
 108   
       final boolean popup,
 109   
       final long sleepTime,
 110   
       final int position,
 111   
       final Point ref) {
 112  24
     super.validateEvent(event, tc, tp, clicks, modifiers, popup, sleepTime,
 113   
                         position, ref);
 114  24
     assertEquals("Index:", index, event.getTabIndex());
 115  24
     assertEquals("Title:", title, event.getTitle());
 116  24
     assertSameOrNull("Source:", tp, event.getSource());
 117   
   }
 118   
 
 119   
   /**
 120   
    * Test the constructor.
 121   
    */
 122  1
   public void testJTabbedPaneMouseEventData1() {
 123  1
     m_event1 = new JTabbedPaneMouseEventData();
 124  1
     assertEquals("Should be invalid", false, m_event1.isValid());
 125  1
     assertEquals("Prepare result:", false, m_event1.prepareComponent());
 126   
   }
 127   
 
 128   
   /**
 129   
    * Test the constructor.
 130   
    */
 131  1
   public void testJTabbedPaneMouseEventData2() {
 132  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, 1);
 133  1
     validateEvent(m_event1, this, TB1, 1, DEFAULT_TITLE, 1,
 134   
                   DEFAULT_MOUSE_MODIFIERS, DEFAULT_ISPOPUPTRIGGER,
 135   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 136   
 
 137  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, 2);
 138  1
     validateEvent(m_event2, this, TB2, 2, DEFAULT_TITLE, 2,
 139   
                   DEFAULT_MOUSE_MODIFIERS, DEFAULT_ISPOPUPTRIGGER,
 140   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 141   
   }
 142   
 
 143   
   /**
 144   
    * Test the constructor.
 145   
    */
 146  1
   public void testJTabbedPaneMouseEventData2b() {
 147  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1);
 148  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, DEFAULT_MOUSE_MODIFIERS,
 149   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 150   
 
 151  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, TITLE2, 2);
 152  1
     validateEvent(m_event2, this, TB2, 2, TITLE2, 2, DEFAULT_MOUSE_MODIFIERS,
 153   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 154   
   }
 155   
 
 156   
   /**
 157   
    * Test the constructor.
 158   
    */
 159  1
   public void testJTabbedPaneMouseEventData2a() {
 160  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, 1, false);
 161  1
     validateEvent(m_event1, this, TB1, 1, DEFAULT_TITLE, 1,
 162   
                   DEFAULT_MOUSE_MODIFIERS, false, DEFAULT_SLEEPTIME,
 163   
                   DEFAULT_POSITION, null);
 164   
 
 165  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, 2, true);
 166  1
     validateEvent(m_event2, this, TB2, 2, DEFAULT_TITLE, 2,
 167   
                   MouseEvent.BUTTON3_MASK, true, DEFAULT_SLEEPTIME,
 168   
                   DEFAULT_POSITION, null);
 169   
   }
 170   
 
 171   
   /**
 172   
    * Test the constructor.
 173   
    */
 174  1
   public void testJTabbedPaneMouseEventData2aa() {
 175  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1, false);
 176  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, DEFAULT_MOUSE_MODIFIERS, false,
 177   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 178   
 
 179  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, TITLE2, 2, true);
 180  1
     validateEvent(m_event2, this, TB2, 2, TITLE2, 2, MouseEvent.BUTTON3_MASK, true,
 181   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 182   
   }
 183   
 
 184   
   /**
 185   
    * Test the constructor.
 186   
    */
 187  1
   public void testJTabbedPaneMouseEventData3() {
 188  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, 1, 500);
 189  1
     validateEvent(m_event1, this, TB1, 1, DEFAULT_TITLE, 1,
 190   
                   DEFAULT_MOUSE_MODIFIERS, DEFAULT_ISPOPUPTRIGGER, 500,
 191   
                   DEFAULT_POSITION, null);
 192   
 
 193  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 3, 2, 1500);
 194  1
     validateEvent(m_event2, this, TB2, 3, DEFAULT_TITLE, 2,
 195   
                   DEFAULT_MOUSE_MODIFIERS, DEFAULT_ISPOPUPTRIGGER, 1500,
 196   
                   DEFAULT_POSITION, null);
 197   
   }
 198   
 
 199   
   /**
 200   
    * Test the constructor.
 201   
    */
 202  1
   public void testJTabbedPaneMouseEventData3a() {
 203  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, 1, false, 500);
 204  1
     validateEvent(m_event1, this, TB1, 1, DEFAULT_TITLE, 1,
 205   
                   DEFAULT_MOUSE_MODIFIERS, false, 500, DEFAULT_POSITION, null);
 206   
 
 207  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 3, 2, true, 1500);
 208  1
     validateEvent(m_event2, this, TB2, 3, DEFAULT_TITLE, 2,
 209   
                   MouseEvent.BUTTON3_MASK, true, 1500, DEFAULT_POSITION, null);
 210   
   }
 211   
 
 212   
   /**
 213   
    * Test the constructor.
 214   
    */
 215  1
   public void testJTabbedPaneMouseEventData3aa() {
 216  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1, false,
 217   
                                              500);
 218  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, DEFAULT_MOUSE_MODIFIERS, false,
 219   
                   500, DEFAULT_POSITION, null);
 220   
 
 221  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 3, TITLE2, 2, true,
 222   
                                              1500);
 223  1
     validateEvent(m_event2, this, TB2, 3, TITLE2, 2, MouseEvent.BUTTON3_MASK, true,
 224   
                   1500, DEFAULT_POSITION, null);
 225   
   }
 226   
 
 227   
   /**
 228   
    * Test the constructor.
 229   
    */
 230  1
   public void testJTabbedPaneMouseEventData3b() {
 231  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1, 500);
 232  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, DEFAULT_MOUSE_MODIFIERS,
 233   
                   DEFAULT_ISPOPUPTRIGGER, 500, DEFAULT_POSITION, null);
 234   
 
 235  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 3, TITLE2, 2, 1500);
 236  1
     validateEvent(m_event2, this, TB2, 3, TITLE2, 2, DEFAULT_MOUSE_MODIFIERS,
 237   
                   DEFAULT_ISPOPUPTRIGGER, 1500, DEFAULT_POSITION, null);
 238   
   }
 239   
 
 240   
   /**
 241   
    * Test the constructor.
 242   
    */
 243  1
   public void testJTabbedPaneMouseEventData4() {
 244  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 245   
                                              MODIFIERS1, true, 500);
 246  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, MODIFIERS1, true, 500,
 247   
                   DEFAULT_POSITION, null);
 248   
 
 249  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, TITLE2, 2,
 250   
                                              MODIFIERS2, false, 1500);
 251  1
     validateEvent(m_event2, this, TB2, 2, TITLE2, 2, MODIFIERS2, false, 1500,
 252   
                   DEFAULT_POSITION, null);
 253   
   }
 254   
 
 255   
   /**
 256   
    * Test the constructor.
 257   
    */
 258  1
   public void testJTabbedPaneMouseEventData5() {
 259  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 260   
                                              MODIFIERS1, true, 500, P1);
 261  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, MODIFIERS1, true, 500,
 262   
                   CUSTOM, P1);
 263   
 
 264  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, TITLE2, 2,
 265   
                                              MODIFIERS2, false, 1500, P2);
 266  1
     validateEvent(m_event2, this, TB2, 2, TITLE2, 2, MODIFIERS2, false, 1500,
 267   
                   CUSTOM, P2);
 268   
   }
 269   
 
 270   
   /**
 271   
    * Test the constructor.
 272   
    */
 273  1
   public void testJTabbedPaneMouseEventData6() {
 274  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 275   
                                              MODIFIERS1, true, 500, WEST);
 276  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, MODIFIERS1, true, 500,
 277   
                   WEST, null);
 278   
 
 279  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, TITLE2, 2,
 280   
                                              MODIFIERS2, false, 1500,
 281   
                                              NORTH_WEST);
 282  1
     validateEvent(m_event2, this, TB2, 2, TITLE2, 2, MODIFIERS2, false, 1500,
 283   
                   NORTH_WEST, null);
 284   
   }
 285   
 
 286   
   /**
 287   
    * Test the constructor.
 288   
    */
 289  1
   public void testJTabbedPaneMouseEventData7() {
 290  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 291   
                                              MODIFIERS1, true, 500, CUSTOM, P1);
 292  1
     validateEvent(m_event1, this, TB1, 1, TITLE1, 1, MODIFIERS1, true, 500,
 293   
                   CUSTOM, P1);
 294   
 
 295  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, TITLE2, 2,
 296   
                                              MODIFIERS2, false, 1500, PERCENT,
 297   
                                              P2);
 298  1
     validateEvent(m_event2, this, TB2, 2, TITLE2, 2, MODIFIERS2, false, 1500,
 299   
                   PERCENT, P2);
 300   
   }
 301   
 
 302   
   /**
 303   
    * Test the equals.
 304   
    */
 305  1
   public void testEquals() {
 306  1
     m_event1 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 307   
                                              MODIFIERS1, true, 500, CUSTOM, P1);
 308  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 309   
                                              MODIFIERS1, true, 500, CUSTOM, P1);
 310  1
     assertTrue("Not equals:", m_event1.equals(m_event2));
 311  1
     assertTrue("Null equals:", !m_event1.equals(null));
 312  1
     assertTrue("Invalid class:", !m_event1.equals(""));
 313  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 1, TITLE1, 1,
 314   
                                              MODIFIERS1, true, 500, CUSTOM, P1);
 315  1
     assertTrue("Equals but Component different:", !m_event1.equals(m_event2));
 316  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 2, TITLE1, 1,
 317   
                                              MODIFIERS1, true, 500, CUSTOM, P1);
 318  1
     assertTrue("Equals but Index different:", !m_event1.equals(m_event2));
 319  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE2, 1,
 320   
                                              MODIFIERS1, true, 500, CUSTOM, P1);
 321  1
     assertTrue("Equals but Title different:", !m_event1.equals(m_event2));
 322  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 2,
 323   
                                              MODIFIERS1, true, 500, CUSTOM, P1);
 324  1
     assertTrue("Equals but Clicks different:", !m_event1.equals(m_event2));
 325  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 326   
                                              MODIFIERS2, true, 500, CUSTOM, P1);
 327  1
     assertTrue("Equals but Modifiers different:", !m_event1.equals(m_event2));
 328  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 329   
                                              MODIFIERS1, false, 500, CUSTOM, P1);
 330  1
     assertTrue("Equals but Popup different:", !m_event1.equals(m_event2));
 331  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 332   
                                              MODIFIERS1, true, 500, PERCENT, P1);
 333  1
     assertTrue("Equals but Position different:", !m_event1.equals(m_event2));
 334  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB1, 1, TITLE1, 1,
 335   
                                              MODIFIERS1, true, 500, CUSTOM, P2);
 336  1
     assertTrue("Equals but Reference different:", !m_event1.equals(m_event2));
 337  1
     m_event2 = new JTabbedPaneMouseEventData(this, TB2, 2, TITLE2, 2,
 338   
                                              MODIFIERS2, false, 500, PERCENT,
 339   
                                              P2);
 340  1
     assertTrue("Equals but All different:", !m_event1.equals(m_event2));
 341   
   }
 342   
 
 343   
   /**
 344   
    * This method is used to test that when the JTabPane item's width is much greater
 345   
    * than the view port, the click point is recalculated correctly.
 346   
    */
 347  1
   public void testPrepareComponentWithCenterPointOutsideVisibleArea() {
 348  1
     final Vector msgs = new Vector();
 349  1
     setHelper(new JFCTestHelper());
 350  1
     String longString = "with a very long, long line - hope that this is"
 351   
        + " enough. Is this enough? No? Ok, lets go some more - is this ok?"
 352   
        + " Finally!";
 353  1
     setWindow(createJFrame(getName()));
 354   
     // for this test, the frame should not contain the full width of the JList items
 355  1
     getFrame().setSize(35, 100);
 356   
 
 357  1
     MouseListener ml = new MouseAdapter() {
 358  30
       public void mouseClicked(final MouseEvent e) {
 359  30
         JTabbedPane source = (JTabbedPane) e.getSource();
 360  30
         msgs.add("Clicks: " + e.getClickCount() + "  on " + source.getName()
 361   
                  + "  comp: " + source.getSelectedComponent().getName());
 362   
       }
 363   
     };
 364   
 
 365  1
     int number = 5;
 366  1
     JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
 367  1
     tabbedPane.setName("TabbedPane");
 368  1
     tabbedPane.addMouseListener(ml);
 369   
 
 370  1
     JPanel panel;
 371  1
     for (int i = 0; i < number; i++) {
 372  5
       panel = new JPanel();
 373  5
       panel.setLayout(new GridBagLayout());
 374  5
       panel.add(new JButton("JButton-" + i));
 375  5
       panel.add(new JButton("JButton2-" + i));
 376  5
       panel.setName("Panel-" + i + longString);
 377  5
       tabbedPane.add(panel);
 378   
     }
 379   
 
 380  1
     JScrollPane scrollPane = new JScrollPane(JScrollPane.
 381   
                                              VERTICAL_SCROLLBAR_AS_NEEDED,
 382   
                                              JScrollPane.
 383   
                                              HORIZONTAL_SCROLLBAR_AS_NEEDED);
 384  1
     scrollPane.setPreferredSize(new Dimension(30, 100));
 385  1
     scrollPane.setViewportView(tabbedPane);
 386   
 
 387  1
     getFrame().getContentPane().add(scrollPane);
 388   
     // do not use the packAndShow() method - since we want the viewport to be smaller than the list width...
 389  1
     JFCUtilities.center(getFrame());
 390  1
     getFrame().setVisible(true);
 391   
 
 392  1
     for (int tries = 0; tries < 10; tries++) {
 393  10
       for (int clicks = 1; clicks < 3; clicks++) {
 394  20
         int idx = (int) (Math.random() * number);
 395  20
         msgs.clear();
 396   
         // non-default isPopupTrigger flag
 397  20
         getHelper().enterClickAndLeave(new JTabbedPaneMouseEventData(this,
 398   
             tabbedPane, idx, clicks, false));
 399  20
         sleep(getSleepTimer());
 400  20
         assertEquals("Number of messages showing is wrong", clicks, msgs.size());
 401  20
         for (int click = 1; click <= clicks; click++) {
 402  30
           assertEquals(
 403   
               "Wrong message is showing up:",
 404   
               "Clicks: " + click + "  on " + tabbedPane.getName() + "  comp: "
 405   
               + tabbedPane.getComponentAt(idx).getName(),
 406   
               msgs.get(click - 1));
 407   
         }
 408   
       }
 409   
     }
 410   
   }
 411   
 }
 412