Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 452   Methods: 23
NCLOC: 275   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JTreeMouseEventDataT.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.Point;
 8   
 import java.awt.event.MouseAdapter;
 9   
 import java.awt.event.MouseEvent;
 10   
 import java.util.Vector;
 11   
 
 12   
 import javax.swing.JScrollPane;
 13   
 import javax.swing.JTree;
 14   
 import javax.swing.tree.DefaultMutableTreeNode;
 15   
 import javax.swing.tree.DefaultTreeModel;
 16   
 import javax.swing.tree.TreePath;
 17   
 
 18   
 import junit.extensions.jfcunit.tools.JFCUtilities;
 19   
 
 20   
 /**
 21   
  * Data container class that holds all the data necessary for jfcUnit to fire mouse events.
 22   
  * This class is specific to events on a JTree.
 23   
  *
 24   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 25   
  */
 26   
 public class JTreeMouseEventDataT
 27   
     extends MouseEventDataBC {
 28   
   /**
 29   
    * Event data to be validated.
 30   
    */
 31   
   private JTreeMouseEventData m_event1 = null;
 32   
 
 33   
   /**
 34   
    * Second Event data to be validated.
 35   
    */
 36   
   private JTreeMouseEventData m_event2 = null;
 37   
 
 38   
   /**
 39   
    * Component to be tested.
 40   
    */
 41   
   private static final JTree T1 = new JTree();
 42   
 
 43   
   /**
 44   
    * Second component to be tested.
 45   
    */
 46   
   private static final JTree T2 = new JTree();
 47   
 
 48   
   /**
 49   
    * Node data to be tested.
 50   
    */
 51   
   private static final String N1 = "Node1";
 52   
 
 53   
   /**
 54   
    * Second node data to be tested.
 55   
    */
 56   
   private static final String N2 = "Node2";
 57   
 
 58   
   /**
 59   
    * Treepath to be tested.
 60   
    */
 61   
   private static final TreePath TP1 = new TreePath(new Object());
 62   
 
 63   
   /**
 64   
    * Second treepath to be tested.
 65   
    */
 66   
   private static final TreePath TP2 = new TreePath(new Object());
 67   
 
 68   
   /**
 69   
    * Default constructor that accepts a String.
 70   
    *
 71   
    * @param   name      The name of the test method to execute.
 72   
    */
 73  19
   public JTreeMouseEventDataT(final String name) {
 74  19
     super(name);
 75   
   }
 76   
 
 77   
   /**
 78   
    * Overridden method that is used to remove the test fixtures.
 79   
    *
 80   
    * @exception  Exception   An instance of java.lang.Exception can be thrown
 81   
    */
 82  19
   protected void tearDown() throws Exception {
 83  19
     super.tearDown();
 84  19
     m_event1 = null;
 85  19
     m_event2 = null;
 86   
   }
 87   
 
 88   
   /**
 89   
    * Validate the parameters of the event match the values
 90   
    * given.
 91   
    *
 92   
    * @param event Event to be tested.
 93   
    * @param tc TestCase
 94   
    * @param tp component
 95   
    * @param node String
 96   
    * @param path Path
 97   
    * @param clicks mouse clicks.
 98   
    * @param modifiers Modifiers to be used.
 99   
    * @param popup Popup
 100   
    * @param sleepTime sleep duration.
 101   
    * @param position locatio of mouse.
 102   
    * @param ref Reference location.
 103   
    */
 104  32
   protected void validateEvent(
 105   
       final JTreeMouseEventData event,
 106   
       final JFCTestCase tc,
 107   
       final JTree tp,
 108   
       final String node,
 109   
       final TreePath path,
 110   
       final int clicks,
 111   
       final int modifiers,
 112   
       final boolean popup,
 113   
       final long sleepTime,
 114   
       final int position,
 115   
       final Point ref) {
 116   
 
 117  32
     super.validateEvent(event, tc, tp, clicks, modifiers, popup, sleepTime,
 118   
                         position, ref);
 119  32
     assertEquals("Node:", node, event.getNodeValue());
 120  32
     assertEquals("Path:", path, event.getTreePath());
 121  32
     assertSameOrNull("Source:", tp, event.getSource());
 122   
   }
 123   
 
 124   
   /**
 125   
    * Test the constructor.
 126   
    */
 127  1
   public void testJTreeMouseEventData2n() {
 128  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1);
 129  1
     validateEvent(m_event1, this, T1, null, TP1, 1, DEFAULT_MOUSE_MODIFIERS,
 130   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 131   
 
 132  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2);
 133  1
     validateEvent(m_event2, this, T2, null, TP2, 2, DEFAULT_MOUSE_MODIFIERS,
 134   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 135   
   }
 136   
 
 137   
   /**
 138   
    * Test the constructor.
 139   
    */
 140  1
   public void testJTreeMouseEventData2na() {
 141  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1, false);
 142  1
     validateEvent(m_event1, this, T1, null, TP1, 1, DEFAULT_MOUSE_MODIFIERS, false,
 143   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 144   
 
 145  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2, true);
 146  1
     validateEvent(m_event2, this, T2, null, TP2, 2, MouseEvent.BUTTON3_MASK, true,
 147   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 148   
   }
 149   
 
 150   
   /**
 151   
    * Test the constructor.
 152   
    */
 153  1
   public void testJTreeMouseEventData3n() {
 154  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1, 500);
 155  1
     validateEvent(m_event1, this, T1, null, TP1, 1, DEFAULT_MOUSE_MODIFIERS,
 156   
                   DEFAULT_ISPOPUPTRIGGER, 500, DEFAULT_POSITION, null);
 157   
 
 158  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2, 1500);
 159  1
     validateEvent(m_event2, this, T2, null, TP2, 2, DEFAULT_MOUSE_MODIFIERS,
 160   
                   DEFAULT_ISPOPUPTRIGGER, 1500, DEFAULT_POSITION, null);
 161   
   }
 162   
 
 163   
   /**
 164   
    * Test the constructor.
 165   
    */
 166  1
   public void testJTreeMouseEventData3na() {
 167  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1, false, 500);
 168  1
     validateEvent(m_event1, this, T1, null, TP1, 1, DEFAULT_MOUSE_MODIFIERS, false,
 169   
                   500, DEFAULT_POSITION, null);
 170   
 
 171  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2, true, 1500);
 172  1
     validateEvent(m_event2, this, T2, null, TP2, 2, MouseEvent.BUTTON3_MASK, true,
 173   
                   1500, DEFAULT_POSITION, null);
 174   
   }
 175   
 
 176   
   /**
 177   
    * Test the constructor.
 178   
    */
 179  1
   public void testJTreeMouseEventData4n() {
 180  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1, MODIFIERS1, true, 500);
 181  1
     validateEvent(m_event1, this, T1, null, TP1, 1, MODIFIERS1, true, 500,
 182   
                   DEFAULT_POSITION, null);
 183   
 
 184  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2, MODIFIERS2, false,
 185   
                                        1500);
 186  1
     validateEvent(m_event2, this, T2, null, TP2, 2, MODIFIERS2, false, 1500,
 187   
                   DEFAULT_POSITION, null);
 188   
   }
 189   
 
 190   
   /**
 191   
    * Test the constructor.
 192   
    */
 193  1
   public void testJTreeMouseEventData5n() {
 194  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1, MODIFIERS1, true, 500,
 195   
                                        P1);
 196  1
     validateEvent(m_event1, this, T1, null, TP1, 1, MODIFIERS1, true, 500,
 197   
                   CUSTOM, P1);
 198   
 
 199  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2, MODIFIERS2, false,
 200   
                                        1500, P2);
 201  1
     validateEvent(m_event2, this, T2, null, TP2, 2, MODIFIERS2, false, 1500,
 202   
                   CUSTOM, P2);
 203   
   }
 204   
 
 205   
   /**
 206   
    * Test the constructor.
 207   
    */
 208  1
   public void testJTreeMouseEventData6n() {
 209  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1, MODIFIERS1, true, 500,
 210   
                                        WEST);
 211  1
     validateEvent(m_event1, this, T1, null, TP1, 1, MODIFIERS1, true, 500, WEST, null);
 212   
 
 213  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2, MODIFIERS2, false,
 214   
                                        1500, NORTH_WEST);
 215  1
     validateEvent(m_event2, this, T2, null, TP2, 2, MODIFIERS2, false, 1500,
 216   
                   NORTH_WEST, null);
 217   
   }
 218   
 
 219   
   /**
 220   
    * Test the constructor.
 221   
    */
 222  1
   public void testJTreeMouseEventData7n() {
 223  1
     m_event1 = new JTreeMouseEventData(this, T1, TP1, 1, MODIFIERS1, true, 500,
 224   
                                        CUSTOM, P1);
 225  1
     validateEvent(m_event1, this, T1, null, TP1, 1, MODIFIERS1, true, 500,
 226   
                   CUSTOM, P1);
 227   
 
 228  1
     m_event2 = new JTreeMouseEventData(this, T2, TP2, 2, MODIFIERS2, false,
 229   
                                        1500, PERCENT, P2);
 230  1
     validateEvent(m_event2, this, T2, null, TP2, 2, MODIFIERS2, false, 1500,
 231   
                   PERCENT, P2);
 232   
   }
 233   
 
 234   
   /**
 235   
    * Test the constructor.
 236   
    */
 237  1
   public void testJTreeMouseEventData1() {
 238  1
     m_event1 = new JTreeMouseEventData();
 239  1
     assertEquals("Should be invalid", false, m_event1.isValid());
 240  1
     assertEquals("Prepare result:", false, m_event1.prepareComponent());
 241   
   }
 242   
 
 243   
   /**
 244   
    * Test the constructor.
 245   
    */
 246  1
   public void testJTreeMouseEventData2p() {
 247  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1);
 248  1
     validateEvent(m_event1, this, T1, N1, null, 1, DEFAULT_MOUSE_MODIFIERS,
 249   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 250   
 
 251  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2);
 252  1
     validateEvent(m_event2, this, T2, N2, null, 2, DEFAULT_MOUSE_MODIFIERS,
 253   
                   DEFAULT_ISPOPUPTRIGGER, DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 254   
   }
 255   
 
 256   
   /**
 257   
    * Test the constructor.
 258   
    */
 259  1
   public void testJTreeMouseEventData2pa() {
 260  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, false);
 261  1
     validateEvent(m_event1, this, T1, N1, null, 1, DEFAULT_MOUSE_MODIFIERS, false,
 262   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 263   
 
 264  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, true);
 265  1
     validateEvent(m_event2, this, T2, N2, null, 2, MouseEvent.BUTTON3_MASK, true,
 266   
                   DEFAULT_SLEEPTIME, DEFAULT_POSITION, null);
 267   
   }
 268   
 
 269   
   /**
 270   
    * Test the constructor.
 271   
    */
 272  1
   public void testJTreeMouseEventData3p() {
 273  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, 500);
 274  1
     validateEvent(m_event1, this, T1, N1, null, 1, DEFAULT_MOUSE_MODIFIERS,
 275   
                   DEFAULT_ISPOPUPTRIGGER, 500, DEFAULT_POSITION, null);
 276   
 
 277  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, 1500);
 278  1
     validateEvent(m_event2, this, T2, N2, null, 2, DEFAULT_MOUSE_MODIFIERS,
 279   
                   DEFAULT_ISPOPUPTRIGGER, 1500, DEFAULT_POSITION, null);
 280   
   }
 281   
 
 282   
   /**
 283   
    * Test the constructor.
 284   
    */
 285  1
   public void testJTreeMouseEventData3pa() {
 286  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, false, 500);
 287  1
     validateEvent(m_event1, this, T1, N1, null, 1, DEFAULT_MOUSE_MODIFIERS, false,
 288   
                   500, DEFAULT_POSITION, null);
 289   
 
 290  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, true, 1500);
 291  1
     validateEvent(m_event2, this, T2, N2, null, 2, MouseEvent.BUTTON3_MASK, true,
 292   
                   1500, DEFAULT_POSITION, null);
 293   
   }
 294   
 
 295   
   /**
 296   
    * Test the constructor.
 297   
    */
 298  1
   public void testJTreeMouseEventData4p() {
 299  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500);
 300  1
     validateEvent(m_event1, this, T1, N1, null, 1, MODIFIERS1, true, 500,
 301   
                   DEFAULT_POSITION, null);
 302   
 
 303  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, MODIFIERS2, false, 1500);
 304  1
     validateEvent(m_event2, this, T2, N2, null, 2, MODIFIERS2, false, 1500,
 305   
                   DEFAULT_POSITION, null);
 306   
   }
 307   
 
 308   
   /**
 309   
    * Test the constructor.
 310   
    */
 311  1
   public void testJTreeMouseEventData5p() {
 312  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500,
 313   
                                        P1);
 314  1
     validateEvent(m_event1, this, T1, N1, null, 1, MODIFIERS1, true, 500,
 315   
                   CUSTOM, P1);
 316   
 
 317  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, MODIFIERS2, false, 1500,
 318   
                                        P2);
 319  1
     validateEvent(m_event2, this, T2, N2, null, 2, MODIFIERS2, false, 1500,
 320   
                   CUSTOM, P2);
 321   
   }
 322   
 
 323   
   /**
 324   
    * Test the constructor.
 325   
    */
 326  1
   public void testJTreeMouseEventData6p() {
 327  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500,
 328   
                                        WEST);
 329  1
     validateEvent(m_event1, this, T1, N1, null, 1, MODIFIERS1, true, 500, WEST, null);
 330   
 
 331  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, MODIFIERS2, false, 1500,
 332   
                                        NORTH_WEST);
 333  1
     validateEvent(m_event2, this, T2, N2, null, 2, MODIFIERS2, false, 1500,
 334   
                   NORTH_WEST, null);
 335   
   }
 336   
 
 337   
   /**
 338   
    * Test the constructor.
 339   
    */
 340  1
   public void testJTreeMouseEventData7p() {
 341  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500,
 342   
                                        CUSTOM, P1);
 343  1
     validateEvent(m_event1, this, T1, N1, null, 1, MODIFIERS1, true, 500,
 344   
                   CUSTOM, P1);
 345   
 
 346  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, MODIFIERS2, false, 1500,
 347   
                                        PERCENT, P2);
 348  1
     validateEvent(m_event2, this, T2, N2, null, 2, MODIFIERS2, false, 1500,
 349   
                   PERCENT, P2);
 350   
   }
 351   
 
 352   
   /**
 353   
    * Test the equals.
 354   
    */
 355  1
   public void testEquals() {
 356  1
     m_event1 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500,
 357   
                                        CUSTOM, P1);
 358  1
     m_event2 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500,
 359   
                                        CUSTOM, P1);
 360  1
     assertTrue("Not equals:", m_event1.equals(m_event2));
 361  1
     assertTrue("Null equals:", !m_event1.equals(null));
 362  1
     assertTrue("Invalid class:", !m_event1.equals(new String()));
 363  1
     m_event2 = new JTreeMouseEventData(this, T2, N1, 1, MODIFIERS1, true, 500,
 364   
                                        CUSTOM, P1);
 365  1
     assertTrue("Equals but Component different:", !m_event1.equals(m_event2));
 366  1
     m_event2 = new JTreeMouseEventData(this, T1, N2, 1, MODIFIERS1, true, 500,
 367   
                                        CUSTOM, P1);
 368  1
     assertTrue("Equals but Node different:", !m_event1.equals(m_event2));
 369  1
     m_event2 = new JTreeMouseEventData(this, T1, N1, 2, MODIFIERS1, true, 500,
 370   
                                        CUSTOM, P1);
 371  1
     assertTrue("Equals but Clicks different:", !m_event1.equals(m_event2));
 372  1
     m_event2 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS2, true, 500,
 373   
                                        CUSTOM, P1);
 374  1
     assertTrue("Equals but Modifiers different:", !m_event1.equals(m_event2));
 375  1
     m_event2 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, false, 500,
 376   
                                        CUSTOM, P1);
 377  1
     assertTrue("Equals but Popup different:", !m_event1.equals(m_event2));
 378  1
     m_event2 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500,
 379   
                                        PERCENT, P1);
 380  1
     assertTrue("Equals but Position different:", !m_event1.equals(m_event2));
 381  1
     m_event2 = new JTreeMouseEventData(this, T1, N1, 1, MODIFIERS1, true, 500,
 382   
                                        CUSTOM, P2);
 383  1
     assertTrue("Equals but Reference different:", !m_event1.equals(m_event2));
 384  1
     m_event2 = new JTreeMouseEventData(this, T2, N2, 2, MODIFIERS2, false, 1500,
 385   
                                        PERCENT, P2);
 386  1
     assertTrue("Equals but All different:", !m_event1.equals(m_event2));
 387   
   }
 388   
 
 389   
   /**
 390   
        * This method is used to test that when the JTree item's width is much greater
 391   
    * than the view port, the click point is recalculated correctly.
 392   
    */
 393  1
   public void testPrepareComponentWithCenterPointOutsideVisibleArea() {
 394  1
     final String longString = " Trying to get a really looooooong string"
 395   
        + " together to test the huge width issue within a narrow view port.";
 396  1
     final Vector msgs = new Vector();
 397  1
     setHelper(new JFCTestHelper());
 398  1
     setWindow(createJFrame(getName()));
 399   
     // for this test, the frame should not contain the full width of the JList items
 400  1
     getFrame().setSize(35, 100);
 401   
 
 402   
     // set up the tree
 403  1
     DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root Node");
 404  1
     DefaultTreeModel model = new DefaultTreeModel(root);
 405  1
     JTree tree = new JTree(model);
 406  1
     tree.setName("Test JTree");
 407  1
     tree.addMouseListener(new MouseAdapter() {
 408  3
       public void mousePressed(final MouseEvent e) {
 409  3
         msgs.add(new String(e.getClickCount() + " click(s) on tree"));
 410   
       }
 411   
     });
 412   
 
 413   
     // add two items at level
 414  1
     DefaultMutableTreeNode level1Node = null;
 415  1
     DefaultMutableTreeNode level2Node = null;
 416   
 
 417  1
     for (int i = 0; i < 2; i++) {
 418  2
       level1Node = new DefaultMutableTreeNode("Level1-" + i + longString);
 419  2
       root.add(level1Node);
 420   
       // add 3 items at level 2
 421  2
       for (int j = 0; j < 3; j++) {
 422  6
         level2Node = new DefaultMutableTreeNode("Level2-" + j + longString);
 423  6
         level1Node.add(level2Node);
 424   
       }
 425   
     }
 426   
 
 427  1
     JScrollPane scrollPane = new JScrollPane(JScrollPane.
 428   
                                              VERTICAL_SCROLLBAR_AS_NEEDED,
 429   
                                              JScrollPane.
 430   
                                              HORIZONTAL_SCROLLBAR_AS_NEEDED);
 431  1
     scrollPane.setPreferredSize(new Dimension(30, 100));
 432  1
     scrollPane.setViewportView(tree);
 433   
 
 434  1
     getFrame().getContentPane().add(scrollPane);
 435   
     // do not use the packAndShow() method - since we want the viewport to be smaller than the tree width...
 436  1
     JFCUtilities.center(getFrame());
 437  1
     getFrame().setVisible(true);
 438   
 
 439  1
     for (int clicks = 1; clicks < 3; clicks++) {
 440  2
       msgs.clear();
 441  2
       getHelper().enterClickAndLeave(new JTreeMouseEventData(this, tree,
 442   
           level2Node.getUserObject().toString(), clicks));
 443  2
       sleep(getSleepTimer());
 444  2
       assertEquals("Number of messages showing is wrong", clicks, msgs.size());
 445  2
       for (int click = 1; click <= clicks; click++) {
 446  3
         assertEquals("Wrong  is message is showing up",
 447   
                      click + " click(s) on tree", msgs.get(click - 1));
 448   
       }
 449   
     }
 450   
   }
 451   
 }
 452