|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| KeyEventDataT.java | - | 100% | 100% | 100% |
|
||||||||||||||
| 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 KeyEventDataT extends JFCTestCase implements EventDataConstants { |
|
| 16 |
/**
|
|
| 17 |
* Event data to be validated.
|
|
| 18 |
*/
|
|
| 19 |
private KeyEventData m_event1 = null; |
|
| 20 |
|
|
| 21 |
/**
|
|
| 22 |
* Second Event data to be validated.
|
|
| 23 |
*/
|
|
| 24 |
private KeyEventData 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 |
* A key to be tested.
|
|
| 38 |
*/
|
|
| 39 |
private static final int K1 = KeyEvent.VK_F10; |
|
| 40 |
|
|
| 41 |
/**
|
|
| 42 |
* A second key to be tested.
|
|
| 43 |
*/
|
|
| 44 |
private static final int K2 = KeyEvent.VK_HOME; |
|
| 45 |
|
|
| 46 |
/**
|
|
| 47 |
* Modifiers to be tested.
|
|
| 48 |
*/
|
|
| 49 |
private static final int MODIFIERS1 = KeyEvent.SHIFT_MASK; |
|
| 50 |
|
|
| 51 |
/**
|
|
| 52 |
* Second modifiers 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 | 5 |
public KeyEventDataT(final String name) {
|
| 62 | 5 |
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 | 5 |
protected void tearDown() throws Exception { |
| 71 | 5 |
super.tearDown();
|
| 72 | 5 |
m_event1 = null;
|
| 73 | 5 |
m_event2 = null;
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
/**
|
|
| 77 |
* Validate the event was created with the values.
|
|
| 78 |
*
|
|
| 79 |
* @param event Event to be validated.
|
|
| 80 |
* @param tc TestCase
|
|
| 81 |
* @param comp Component
|
|
| 82 |
* @param s key code
|
|
| 83 |
* @param modifiers Modifiers
|
|
| 84 |
* @param sleepTime Sleep duration.
|
|
| 85 |
*/
|
|
| 86 | 6 |
public void validateEvent(final KeyEventData event, |
| 87 |
final JFCTestCase tc, |
|
| 88 |
final Component comp, |
|
| 89 |
final int s,
|
|
| 90 |
final int modifiers,
|
|
| 91 |
final long sleepTime) {
|
|
| 92 |
|
|
| 93 | 6 |
assertSame("TestCase:", tc, event.getTestCase());
|
| 94 | 6 |
assertSame("Source:", comp, event.getSource());
|
| 95 | 6 |
assertSame("Component:", comp, event.getComponent());
|
| 96 | 6 |
assertEquals("KeyCode:", s, event.getKeyCode());
|
| 97 | 6 |
assertEquals("Modifiers:", modifiers, event.getModifiers());
|
| 98 | 6 |
assertEquals("SleepTime:", sleepTime, event.getSleepTime());
|
| 99 |
} |
|
| 100 |
|
|
| 101 |
/**
|
|
| 102 |
* Test the constructor.
|
|
| 103 |
*/
|
|
| 104 | 1 |
public void testKeyEventData0() { |
| 105 | 1 |
m_event1 = new KeyEventData();
|
| 106 | 1 |
assertEquals("isValid:", false, m_event1.isValid()); |
| 107 |
|
|
| 108 | 1 |
assertEquals("Prepare result:", false, m_event1.prepareComponent()); |
| 109 |
} |
|
| 110 |
|
|
| 111 |
/**
|
|
| 112 |
* Test the constructor.
|
|
| 113 |
*/
|
|
| 114 | 1 |
public void testKeyEventData1() { |
| 115 | 1 |
m_event1 = new KeyEventData(this, C1, K1); |
| 116 | 1 |
validateEvent(m_event1, this, C1, K1, DEFAULT_KEY_MODIFIERS, DEFAULT_SLEEPTIME);
|
| 117 |
|
|
| 118 | 1 |
m_event2 = new KeyEventData(this, C2, K2); |
| 119 | 1 |
validateEvent(m_event2, this, C2, K2, DEFAULT_KEY_MODIFIERS, DEFAULT_SLEEPTIME);
|
| 120 |
|
|
| 121 | 1 |
assertTrue("Values compare equal", !m_event1.equals(m_event2));
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
/**
|
|
| 125 |
* Test the constructor.
|
|
| 126 |
*/
|
|
| 127 | 1 |
public void testKeyEventData2() { |
| 128 | 1 |
m_event1 = new KeyEventData(this, C1, K1, 1000); |
| 129 | 1 |
validateEvent(m_event1, this, C1, K1, DEFAULT_KEY_MODIFIERS, 1000);
|
| 130 |
|
|
| 131 | 1 |
m_event2 = new KeyEventData(this, C2, K2, 2000); |
| 132 | 1 |
validateEvent(m_event2, this, C2, K2, DEFAULT_KEY_MODIFIERS, 2000);
|
| 133 |
|
|
| 134 | 1 |
assertTrue("Values compare equal", !m_event1.equals(m_event2));
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
/**
|
|
| 138 |
* Test the constructor.
|
|
| 139 |
*/
|
|
| 140 | 1 |
public void testKeyEventData3() { |
| 141 | 1 |
m_event1 = new KeyEventData(this, C1, K1, MODIFIERS1, 1000); |
| 142 | 1 |
validateEvent(m_event1, this, C1, K1, MODIFIERS1, 1000);
|
| 143 |
|
|
| 144 | 1 |
m_event2 = new KeyEventData(this, C2, K2, MODIFIERS2, 2000); |
| 145 | 1 |
validateEvent(m_event2, this, C2, K2, MODIFIERS2, 2000);
|
| 146 |
|
|
| 147 | 1 |
assertTrue("Values compare equal", !m_event1.equals(m_event2));
|
| 148 |
} |
|
| 149 |
|
|
| 150 |
/**
|
|
| 151 |
* Test the equality.
|
|
| 152 |
*/
|
|
| 153 | 1 |
public void testEquals() { |
| 154 | 1 |
m_event1 = new KeyEventData(this, C1, K1, MODIFIERS1, 1000); |
| 155 | 1 |
m_event2 = new KeyEventData(this, C1, K1, MODIFIERS1, 1000); |
| 156 | 1 |
assertTrue("Not equals:", m_event1.equals(m_event2));
|
| 157 | 1 |
assertTrue("Null equals:", !m_event1.equals(null)); |
| 158 | 1 |
assertTrue("Invalid class:", !m_event1.equals("")); |
| 159 | 1 |
m_event2 = new KeyEventData(this, C2, K1, MODIFIERS1, 1000); |
| 160 | 1 |
assertTrue("Equals but Component different:", !m_event1.equals(m_event2));
|
| 161 | 1 |
m_event2 = new KeyEventData(this, C1, K2, MODIFIERS1, 1000); |
| 162 | 1 |
assertTrue("Equals but Code different:", !m_event1.equals(m_event2));
|
| 163 | 1 |
m_event2 = new KeyEventData(this, C1, K1, MODIFIERS2, 1000); |
| 164 | 1 |
assertTrue("Equals but Modifiers different:", !m_event1.equals(m_event2));
|
| 165 |
} |
|
| 166 |
} |
|
| 167 |
|
|
||||||||||