Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 170   Methods: 9
NCLOC: 77   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StringEventDataT.java - 100% 100% 100%
coverage
 1   
 package junit.extensions.jfcunit.eventdata;
 2   
 
 3   
 import junit.extensions.jfcunit.JFCTestCase;
 4   
 
 5   
 import java.awt.Component;
 6   
 import java.awt.event.KeyEvent;
 7   
 
 8   
 import javax.swing.JTextField;
 9   
 
 10   
 /**
 11   
  * Data container class that holds all the data necessary for jfcUnit to fire mouse events.
 12   
  *
 13   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 14   
  */
 15   
 public class StringEventDataT extends JFCTestCase implements EventDataConstants {
 16   
     /**
 17   
      * Event data to be validated.
 18   
      */
 19   
     private StringEventData m_event1 = null;
 20   
 
 21   
     /**
 22   
      * Second Event data to be validated.
 23   
      */
 24   
     private StringEventData m_event2 = null;
 25   
 
 26   
     /**
 27   
      * Component to be tested.
 28   
      */
 29   
     private static final Component C1 = new JTextField();
 30   
 
 31   
     /**
 32   
      * Second component to be tested.
 33   
      */
 34   
     private static final Component C2 = new JTextField();
 35   
 
 36   
     /**
 37   
      * String to be tested.
 38   
      */
 39   
     private static final String S1 = "ABC";
 40   
 
 41   
     /**
 42   
      * String to be tested.
 43   
      */
 44   
     private static final String S2 = "ZED";
 45   
 
 46   
     /**
 47   
      * Modifier to be tested.
 48   
      */
 49   
     private static final int MODIFIERS1 = KeyEvent.SHIFT_MASK;
 50   
 
 51   
     /**
 52   
      * Second modifier to be tested.
 53   
      */
 54   
     private static final int MODIFIERS2 = KeyEvent.CTRL_MASK;
 55   
 
 56   
     /**
 57   
      * Default constructor that accepts a String.
 58   
      *
 59   
      * @param   name      The name of the test method to execute.
 60   
      */
 61  6
     public StringEventDataT(final String name) {
 62  6
         super(name);
 63   
     }
 64   
 
 65   
     /**
 66   
      * Overridden method that is used to remove the test fixtures.
 67   
      *
 68   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 69   
      */
 70  6
     protected void tearDown() throws Exception {
 71  6
         super.tearDown();
 72  6
         m_event1 = null;
 73  6
         m_event2 = null;
 74   
     }
 75   
 
 76   
     /**
 77   
      * Validate the event was created properly.
 78   
      *
 79   
      * @param event Event to be tested.
 80   
      * @param tc TestCase
 81   
      * @param comp Component
 82   
      * @param s String
 83   
      * @param modifiers Modifiers.
 84   
      * @param sleepTime sleep duration.
 85   
      */
 86  6
     public void validateEvent(final StringEventData event,
 87   
                               final JFCTestCase tc,
 88   
                               final Component comp,
 89   
                               final String s,
 90   
                               final int modifiers,
 91   
                               final long sleepTime) {
 92  6
         assertSame("TestCase:", tc, event.getTestCase());
 93  6
         assertSame("Source:", comp, event.getSource());
 94  6
         assertSame("Component:", comp, event.getComponent());
 95  6
         assertSame("String:", s, event.getString());
 96  6
         assertEquals("Modifiers:", modifiers, event.getModifiers());
 97  6
         assertEquals("SleepTime:", sleepTime, event.getSleepTime());
 98   
     }
 99   
 
 100   
     /**
 101   
      * Test the constructor.
 102   
      */
 103  1
     public void testStringEventData0() {
 104  1
         m_event1 = new StringEventData();
 105  1
         assertEquals("isValid:", false, m_event1.isValid());
 106   
 
 107  1
         assertEquals("Prepare result:", false, m_event1.prepareComponent());
 108   
     }
 109   
 
 110   
     /**
 111   
      * Test the constructor.
 112   
      */
 113  1
     public void testStringEventData1() {
 114  1
         m_event1 = new StringEventData(this, C1, S1);
 115  1
         validateEvent(m_event1, this, C1, S1, DEFAULT_KEY_MODIFIERS, DEFAULT_SLEEPTIME);
 116   
 
 117  1
         m_event2 = new StringEventData(this, C2, S2);
 118  1
         validateEvent(m_event2, this, C2, S2, DEFAULT_KEY_MODIFIERS, DEFAULT_SLEEPTIME);
 119   
     }
 120   
 
 121   
     /**
 122   
      * Test the constructor.
 123   
      */
 124  1
     public void testStringEventData2() {
 125  1
         m_event1 = new StringEventData(this, C1, S1, 1000);
 126  1
         validateEvent(m_event1, this, C1, S1, DEFAULT_KEY_MODIFIERS, 1000);
 127   
 
 128  1
         m_event2 = new StringEventData(this, C2, S2, 2000);
 129  1
         validateEvent(m_event2, this, C2, S2, DEFAULT_KEY_MODIFIERS, 2000);
 130   
     }
 131   
 
 132   
     /**
 133   
      * Test the constructor.
 134   
      */
 135  1
     public void testStringEventData3() {
 136  1
         m_event1 = new StringEventData(this, C1, S1, MODIFIERS1, 1000);
 137  1
         validateEvent(m_event1, this, C1, S1, MODIFIERS1, 1000);
 138   
 
 139  1
         m_event2 = new StringEventData(this, C2, S2, MODIFIERS2, 2000);
 140  1
         validateEvent(m_event2, this, C2, S2, MODIFIERS2, 2000);
 141   
     }
 142   
 
 143   
     /**
 144   
      * Test the equality.
 145   
      */
 146  1
     public void testEquals() {
 147  1
         m_event1 = new StringEventData(this, C1, S1, MODIFIERS1, 1000);
 148  1
         m_event2 = new StringEventData(this, C1, S1, MODIFIERS1, 1000);
 149  1
         assertTrue("Not equals:", m_event1.equals(m_event2));
 150  1
         assertTrue("Null equals:", !m_event1.equals(null));
 151  1
         assertTrue("Invalid class:", !m_event1.equals(new String()));
 152  1
         m_event2 = new StringEventData(this, C2, S1, MODIFIERS1, 1000);
 153  1
         assertTrue("Equals but Component different:", !m_event1.equals(m_event2));
 154  1
         m_event2 = new StringEventData(this, C1, S2, MODIFIERS1, 1000);
 155  1
         assertTrue("Equals but String different:", !m_event1.equals(m_event2));
 156  1
         m_event2 = new StringEventData(this, C1, S1, MODIFIERS2, 1000);
 157  1
         assertTrue("Equals but Modifiers different:", !m_event1.equals(m_event2));
 158   
     }
 159   
 
 160   
     /**
 161   
      * Test the tostring method.
 162   
      */
 163  1
     public void testToString() {
 164  1
       m_event1 = new StringEventData(this, C1, S1, 0, 1000);
 165  1
       String actual = m_event1.toString();
 166  1
       assertNotNull("MessageExpected", actual);
 167   
     }
 168   
 
 169   
 }
 170