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