1 26 27 package net.sourceforge.groboutils.uicapture.v1.event; 28 29 import java.awt.Robot ; 30 import java.awt.Component ; 31 import java.awt.Button ; 32 import java.awt.event.InputEvent ; 33 import java.awt.event.KeyEvent ; 34 35 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 36 import junit.framework.Test; 37 import junit.framework.TestCase; 38 import junit.framework.TestSuite; 39 40 41 48 public class CaptureEventIUTest extends TestCase 49 { 50 53 private static final Class THIS_CLASS = CaptureEventIUTest.class; 54 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 55 56 public CaptureEventIUTest( String name ) 57 { 58 super( name ); 59 } 60 61 62 63 66 67 public void testNoEventConstructor() 68 { 69 CaptureEvent ce = createCaptureEvent(); 70 assertEquals( 71 "Null event in creation must have null event returned.", 72 ce.getInputEvent(), 73 null ); 74 assertEquals( 75 "Must return the passed-in event type.", 76 ce.getEventType(), 77 this.eventType ); 78 assertEquals( 79 "Must not have a valid time of event.", 80 ce.getTimeOfEvent(), 81 -1 ); 82 } 83 84 public void testNullEventConstructor() 85 { 86 InputEvent ie = null; 87 CaptureEvent ce = createCaptureEvent( ie ); 88 assertEquals( 89 "Event passed in creation must be the same event returned.", 90 ce.getInputEvent(), 91 ie ); 92 assertEquals( 93 "Must return the passed-in event type.", 94 ce.getEventType(), 95 this.eventType ); 96 assertEquals( 97 "Must not have a valid time of event.", 98 ce.getTimeOfEvent(), 99 -1 ); 100 } 101 102 public void testEventConstructor() 103 { 104 InputEvent ie = createInputEvent(); 105 CaptureEvent ce = createCaptureEvent( ie ); 106 assertEquals( 107 "Event passed in creation must be the same event returned.", 108 ce.getInputEvent(), 109 ie ); 110 assertEquals( 111 "Must return the passed-in event type.", 112 ce.getEventType(), 113 this.eventType ); 114 assertEquals( 115 "Must not have a valid time of event.", 116 ce.getTimeOfEvent(), 117 ie.getWhen() ); 118 } 119 120 121 122 protected int eventType = -3; 123 protected CaptureEvent createCaptureEvent( InputEvent ie ) 124 { 125 return new CaptureEvent( this.eventType, ie ) { 126 public void performEvent( Robot r ) 127 { 128 } 130 }; 131 } 132 protected CaptureEvent createCaptureEvent() 133 { 134 return new CaptureEvent( this.eventType ) { 135 public void performEvent( Robot r ) 136 { 137 } 139 }; 140 } 141 protected InputEvent createInputEvent() 142 { 143 return new KeyEvent ( createComponent(), 1, 2L, 0, KeyEvent.VK_S ); 144 } 145 protected Component createComponent() 146 { 147 return new Button (); 148 } 149 150 151 154 155 public static Test suite() 156 { 157 TestSuite suite = new TestSuite( THIS_CLASS ); 158 159 return suite; 160 } 161 162 public static void main( String [] args ) 163 { 164 String [] name = { THIS_CLASS.getName() }; 165 166 169 junit.textui.TestRunner.main( name ); 170 } 171 172 176 protected void setUp() throws Exception 177 { 178 super.setUp(); 179 180 } 182 183 184 188 protected void tearDown() throws Exception 189 { 190 192 193 super.tearDown(); 194 } 195 } 196 197 | Popular Tags |