001: /*
002: * @(#)CaptureEventIUTest.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.uicapture.v1.event;
028:
029: import java.awt.Robot;
030: import java.awt.Component;
031: import java.awt.Button;
032: import java.awt.event.InputEvent;
033: import java.awt.event.KeyEvent;
034:
035: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
036: import junit.framework.Test;
037: import junit.framework.TestCase;
038: import junit.framework.TestSuite;
039:
040: /**
041: * Tests the CaptureEvent class.
042: *
043: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
044: * @since Jan 6, 2002
045: * @version $Date: 2003/02/10 22:52:33 $
046: */
047: public class CaptureEventIUTest extends TestCase {
048: //-------------------------------------------------------------------------
049: // Standard JUnit Class-specific declarations
050:
051: private static final Class THIS_CLASS = CaptureEventIUTest.class;
052: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
053:
054: public CaptureEventIUTest(String name) {
055: super (name);
056: }
057:
058: //-------------------------------------------------------------------------
059: // Tests
060:
061: public void testNoEventConstructor() {
062: CaptureEvent ce = createCaptureEvent();
063: assertEquals(
064: "Null event in creation must have null event returned.",
065: ce.getInputEvent(), null);
066: assertEquals("Must return the passed-in event type.", ce
067: .getEventType(), this .eventType);
068: assertEquals("Must not have a valid time of event.", ce
069: .getTimeOfEvent(), -1);
070: }
071:
072: public void testNullEventConstructor() {
073: InputEvent ie = null;
074: CaptureEvent ce = createCaptureEvent(ie);
075: assertEquals(
076: "Event passed in creation must be the same event returned.",
077: ce.getInputEvent(), ie);
078: assertEquals("Must return the passed-in event type.", ce
079: .getEventType(), this .eventType);
080: assertEquals("Must not have a valid time of event.", ce
081: .getTimeOfEvent(), -1);
082: }
083:
084: public void testEventConstructor() {
085: InputEvent ie = createInputEvent();
086: CaptureEvent ce = createCaptureEvent(ie);
087: assertEquals(
088: "Event passed in creation must be the same event returned.",
089: ce.getInputEvent(), ie);
090: assertEquals("Must return the passed-in event type.", ce
091: .getEventType(), this .eventType);
092: assertEquals("Must not have a valid time of event.", ce
093: .getTimeOfEvent(), ie.getWhen());
094: }
095:
096: protected int eventType = -3;
097:
098: protected CaptureEvent createCaptureEvent(InputEvent ie) {
099: return new CaptureEvent(this .eventType, ie) {
100: public void performEvent(Robot r) {
101: // do nothing
102: }
103: };
104: }
105:
106: protected CaptureEvent createCaptureEvent() {
107: return new CaptureEvent(this .eventType) {
108: public void performEvent(Robot r) {
109: // do nothing
110: }
111: };
112: }
113:
114: protected InputEvent createInputEvent() {
115: return new KeyEvent(createComponent(), 1, 2L, 0, KeyEvent.VK_S);
116: }
117:
118: protected Component createComponent() {
119: return new Button();
120: }
121:
122: //-------------------------------------------------------------------------
123: // Standard JUnit declarations
124:
125: public static Test suite() {
126: TestSuite suite = new TestSuite(THIS_CLASS);
127:
128: return suite;
129: }
130:
131: public static void main(String[] args) {
132: String[] name = { THIS_CLASS.getName() };
133:
134: // junit.textui.TestRunner.main( name );
135: // junit.swingui.TestRunner.main( name );
136:
137: junit.textui.TestRunner.main(name);
138: }
139:
140: /**
141: *
142: * @exception Exception thrown under any exceptional condition.
143: */
144: protected void setUp() throws Exception {
145: super .setUp();
146:
147: // set ourself up
148: }
149:
150: /**
151: *
152: * @exception Exception thrown under any exceptional condition.
153: */
154: protected void tearDown() throws Exception {
155: // tear ourself down
156:
157: super.tearDown();
158: }
159: }
|