0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: /**
0018: * @author Dmitry A. Durnev
0019: * @version $Revision$
0020: */package java.awt;
0021:
0022: import java.awt.event.InputEvent;
0023: import java.awt.event.KeyEvent;
0024: import java.awt.peer.ComponentPeer;
0025: import java.beans.PropertyChangeEvent;
0026: import java.beans.PropertyChangeListener;
0027: import java.util.Collections;
0028: import java.util.HashMap;
0029: import java.util.HashSet;
0030: import java.util.Map;
0031: import java.util.Set;
0032:
0033: import junit.framework.TestCase;
0034:
0035: @SuppressWarnings("serial")
0036: public class ComponentTest extends TestCase {
0037: Robot robot;
0038:
0039: public class SimpleComponent extends Component {
0040: }
0041:
0042: public class SimpleContainer extends Container {
0043: }
0044:
0045: /* more complex component for [deprecated] event testing */
0046: @SuppressWarnings("deprecation")
0047: class MyComponent extends Canvas {
0048:
0049: @Override
0050: public boolean gotFocus(Event evt, Object what) {
0051: synchronized (robot) {
0052: return callback(evt);
0053: }
0054: }
0055:
0056: @Override
0057: public boolean lostFocus(Event evt, Object what) {
0058: synchronized (robot) {
0059: return callback(evt);
0060: }
0061: }
0062:
0063: @Override
0064: public boolean keyDown(Event evt, int key) {
0065: synchronized (robot) {
0066: return callback(evt);
0067: }
0068: }
0069:
0070: @Override
0071: public boolean keyUp(Event evt, int key) {
0072: synchronized (robot) {
0073: return callback(evt);
0074: }
0075: }
0076:
0077: @Override
0078: public void paint(Graphics g) {
0079: super .paint(g);
0080: g.setColor(Color.GREEN);
0081: g.fillRect(0, 0, getWidth(), getHeight());
0082: EventQueue.invokeLater(new Runnable() {
0083: public void run() {
0084: paintFlag = true;
0085: }
0086: });
0087: }
0088: }
0089:
0090: @SuppressWarnings("deprecation")
0091: class MoveResizeComponent extends SimpleComponent {
0092: @Override
0093: public void reshape(int x, int y, int w, int h) {
0094: assertTrue(methodCalled);
0095: assertTrue(setBoundsCalled);
0096: assertFalse(reshapeCalled);
0097: reshapeCalled = true;
0098: super .reshape(x, y, w, h);
0099: }
0100:
0101: @Override
0102: public void setBounds(int x, int y, int w, int h) {
0103: assertTrue(methodCalled);
0104: assertFalse(setBoundsCalled);
0105: setBoundsCalled = true;
0106: super .setBounds(x, y, w, h);
0107: }
0108: }
0109:
0110: @SuppressWarnings("deprecation")
0111: class MyButton extends Button {
0112: @Override
0113: public boolean action(Event evt, Object arg1) {
0114: synchronized (robot) {
0115: return callback(evt);
0116: }
0117: }
0118:
0119: @Override
0120: public void paint(Graphics g) {
0121: super .paint(g);
0122: EventQueue.invokeLater(new Runnable() {
0123: public void run() {
0124: paintFlag = true;
0125: }
0126: });
0127: }
0128: }
0129:
0130: @SuppressWarnings("deprecation")
0131: class MyFrame extends Frame {
0132:
0133: @Override
0134: public boolean handleEvent(Event evt) {
0135: synchronized (robot) {
0136: return callback(evt);
0137: }
0138: }
0139:
0140: @Override
0141: public void paint(Graphics g) {
0142: super .paint(g);
0143: g.setColor(Color.BLUE);
0144: g.fillRect(0, 0, getWidth(), getHeight());
0145: EventQueue.invokeLater(new Runnable() {
0146: public void run() {
0147: paintFlag = true;
0148: }
0149: });
0150: }
0151: }
0152:
0153: SimpleComponent tc;
0154: Component myTestComp;
0155: Frame frame;
0156: boolean paintFlag;
0157: boolean listenerCalled, parentListenerCalled;
0158:
0159: private static final Map<Integer, Event> oldEventsMap = new HashMap<Integer, Event>(); //<int, boolean> key: Event id, value: if listener was called
0160:
0161: boolean methodCalled, setBoundsCalled, reshapeCalled;
0162: String propName;
0163: PropertyChangeListener propListener = new PropertyChangeListener() {
0164: public void propertyChange(PropertyChangeEvent pce) {
0165: listenerCalled = true;
0166: propName = pce.getPropertyName();
0167: oldValue = pce.getOldValue();
0168: newValue = pce.getNewValue();
0169: src = pce.getSource();
0170: }
0171: };
0172: Object oldValue, newValue, src;
0173: int waitTime = 3000; //time to wait for events in ms
0174: private Event event; //saved last deprecated Event object
0175: private final int nRetries = 3; //number of times to repeat [robot] actions
0176:
0177: public static void main(String[] args) {
0178: junit.textui.TestRunner.run(ComponentTest.class);
0179:
0180: }
0181:
0182: static void putEvent(int id, Event evt) {
0183: oldEventsMap.put(new Integer(id), evt);
0184: }
0185:
0186: static Event getEvent(int id) {
0187: Object val = oldEventsMap.get(new Integer(id));
0188: if (val instanceof Event) {
0189: return (Event) val;
0190: }
0191: return null;
0192: }
0193:
0194: @Override
0195: protected void setUp() throws Exception {
0196: super .setUp();
0197: tc = new SimpleComponent();
0198: myTestComp = new MyComponent();
0199: cleanPropertyFields();
0200: event = null;
0201: methodCalled = setBoundsCalled = reshapeCalled = false;
0202: }
0203:
0204: public void testCreate() {
0205: assertNotNull(tc);
0206: assertNotNull(myTestComp);
0207: }
0208:
0209: /*
0210: * @see TestCase#tearDown()
0211: */
0212: @Override
0213: protected void tearDown() throws Exception {
0214:
0215: if (frame != null) {
0216: frame.dispose();
0217: Thread.sleep(500);//wait for the frame to be disposed
0218: frame = null;
0219: if (oldEventsMap != null) {
0220: oldEventsMap.clear();
0221: }
0222: }
0223: super .tearDown();
0224:
0225: }
0226:
0227: public final void testSetVisible() {
0228: tc.setVisible(true);
0229: assertTrue(tc.isVisible());
0230: tc.setVisible(false);
0231: assertFalse(tc.isVisible());
0232: }
0233:
0234: public final void testSetSize() {
0235: Dimension s = new Dimension(20, 10);
0236: tc.setSize(s);
0237: assertEquals(s, tc.getSize());
0238: }
0239:
0240: public final void testSetLocation() {
0241: Point p = new Point(20, 10);
0242: tc.setLocation(p);
0243: assertEquals(p, tc.getLocation());
0244: }
0245:
0246: public final void testContains() {
0247: Dimension s = new Dimension(20, 10);
0248: tc.setSize(s);
0249: Point p = new Point(30, 40), p1 = new Point(-10, 0);
0250: tc.setLocation(p);
0251: assertFalse(tc.contains(p1));
0252: assertFalse(tc.contains(p));
0253: assertTrue(tc.contains(new Point(15, 5)));
0254: assertFalse(tc.contains(new Point(20, 5)));
0255: assertFalse(tc.contains(new Point(5, 10)));
0256: }
0257:
0258: public final void testSetPreferredSize() {
0259: Dimension s0 = new Dimension();
0260: assertEquals(tc.getPreferredSize(), s0);
0261: Dimension s = new Dimension(100, 50);
0262: tc.setPreferredSize(s);
0263: assertEquals(tc.getPreferredSize(), s);
0264: tc.setPreferredSize(null);
0265: assertEquals(tc.getPreferredSize(), s0);
0266: }
0267:
0268: public final void testGetPreferredSize() {
0269:
0270: Dimension s0 = new Dimension();
0271: assertEquals(s0, tc.getPreferredSize());
0272: Dimension s = new Dimension(100, 50);
0273: tc.setMinimumSize(s);
0274: assertEquals(s, tc.getPreferredSize());
0275: tc.setMinimumSize(null);
0276: tc.setSize(s = new Dimension(10, 50));
0277: assertEquals(s, tc.getPreferredSize());
0278: }
0279:
0280: //focus:
0281: public final void testSetFocusable() {
0282: assertTrue(tc.isFocusable());
0283: tc.setFocusable(false);
0284: assertFalse(tc.isFocusable());
0285: tc.setFocusable(true);
0286: assertTrue(tc.isFocusable());
0287: }
0288:
0289: public final void testGetFocusCycleRootAncestor() {
0290: assertNull(tc.getFocusCycleRootAncestor());
0291: SimpleContainer tC = new SimpleContainer();
0292: tC.add(tc);
0293: assertNull(tc.getFocusCycleRootAncestor());
0294: tC.setFocusCycleRoot(true);
0295: assertSame(tC, tc.getFocusCycleRootAncestor());
0296: tC.setFocusCycleRoot(false);
0297: assertNull(tc.getFocusCycleRootAncestor());
0298: }
0299:
0300: public final void testIsFocusCycleRoot() {
0301: assertTrue(tc.isFocusCycleRoot(null));
0302: SimpleContainer tC = new SimpleContainer();
0303: tC.add(tc);
0304: assertTrue(tc.isFocusCycleRoot(null));
0305: tC.setFocusCycleRoot(true);
0306: assertTrue(tc.isFocusCycleRoot(tC));
0307: tC.setFocusCycleRoot(false);
0308: assertTrue(tc.isFocusCycleRoot(null));
0309: }
0310:
0311: public final void testSetFocusTraversalKeysEnabled() {
0312: assertTrue(tc.getFocusTraversalKeysEnabled());
0313: tc.setFocusTraversalKeysEnabled(false);
0314: assertFalse(tc.getFocusTraversalKeysEnabled());
0315: }
0316:
0317: public final void testGetFocusTraversalKeys() {
0318: Set<AWTKeyStroke> testSet = Collections.emptySet();
0319: assertEquals(
0320: testSet,
0321: tc
0322: .getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS));
0323: Set<AWTKeyStroke> forSet = tc
0324: .getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
0325: testSet = new HashSet<AWTKeyStroke>();
0326: testSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
0327: testSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
0328: InputEvent.CTRL_DOWN_MASK));
0329: assertEquals(testSet, forSet);
0330: }
0331:
0332: public final void testSetFocusTraversalKeys() {
0333: int keysID = KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS;
0334: assertFalse(tc.areFocusTraversalKeysSet(keysID));
0335: Set<AWTKeyStroke> upSet = new HashSet<AWTKeyStroke>();
0336: upSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_SPACE, 0));
0337: tc.setFocusTraversalKeys(keysID, upSet);
0338: assertTrue(tc.areFocusTraversalKeysSet(keysID));
0339: assertEquals(upSet, tc.getFocusTraversalKeys(keysID));
0340: }
0341:
0342: public final void testAreFocusTraversalKeysSet() {
0343: int id = KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS;
0344: assertFalse(tc.areFocusTraversalKeysSet(id));
0345: Set<AWTKeyStroke> testSet = new HashSet<AWTKeyStroke>();
0346: testSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
0347: testSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
0348: InputEvent.CTRL_DOWN_MASK));
0349: tc.setFocusTraversalKeys(id, testSet);
0350: assertTrue(tc.areFocusTraversalKeysSet(id));
0351:
0352: }
0353:
0354: public void testGetFont() {
0355: // Regression for HARMONY-1605
0356: final Font defaultFont = new Font("Dialog", Font.PLAIN, 12); //$NON-NLS-1$
0357: final Window w = new Window(new Frame());
0358: final Component c = tc;
0359: final Button b = new Button();
0360:
0361: assertNull(w.getFont());
0362: assertNull(c.getFont());
0363: w.add(c);
0364: assertNull(c.getFont());
0365: w.setVisible(true);
0366: assertEquals(defaultFont, w.getFont());
0367: assertEquals(defaultFont, c.getFont());
0368:
0369: assertNull(b.getFont());
0370: b.setVisible(true);
0371: assertNull(b.getFont());
0372: b.setVisible(false);
0373: b.setVisible(true);
0374: assertNull(b.getFont());
0375: new Frame().add(b);
0376: assertNull(b.getFont());
0377: w.add(b);
0378: assertEquals(defaultFont, b.getFont());
0379:
0380: w.setVisible(false);
0381: w.dispose();
0382: // End of regression for HARMONY-1605
0383: }
0384:
0385: private void createRobot() {
0386: try {
0387: robot = new Robot();
0388: } catch (AWTException e) {
0389: e.printStackTrace();
0390: }
0391: }
0392:
0393: private void createFrameAndWait() {
0394: createRobot();
0395: assertNull(frame);
0396: frame = new Frame();
0397: frame.setBounds(0, 0, 100, 100);
0398: myTestComp.setBounds(0, 0, 30, 50);
0399: frame.add(myTestComp);
0400: waitShowWindow(robot, frame);
0401: }
0402:
0403: boolean callback(Event evt) {
0404: synchronized (robot) {
0405: putEvent(evt.id, evt);
0406: robot.notify();
0407: }
0408: return true;
0409: }
0410:
0411: public final void testAction() {
0412: int eventId = Event.ACTION_EVENT;
0413: myTestComp = new MyButton();
0414: createFrameAndWait();
0415: robot.setAutoDelay(700);
0416: Point screenLoc = myTestComp.getLocationOnScreen();
0417: int centerX = myTestComp.getWidth() / 2;
0418: int centerY = myTestComp.getHeight() / 2;
0419: screenLoc.translate(centerX, centerY);
0420: final Point absPos = screenLoc;
0421:
0422: waitForEvent(new Runnable() {
0423: public void run() {
0424: robot.mouseMove(absPos.x, absPos.y);
0425: robot.mousePress(InputEvent.BUTTON1_MASK
0426: | InputEvent.BUTTON2_MASK);
0427: robot.mouseRelease(InputEvent.BUTTON1_MASK
0428: | InputEvent.BUTTON2_MASK);
0429: }
0430: }, eventId, waitTime);
0431: assertNotNull(event);
0432: Event actionEvt = new Event(myTestComp, eventId,
0433: ((Button) myTestComp).getLabel());
0434: actionEvt.modifiers = Event.ALT_MASK;
0435: checkOldEvent(actionEvt);
0436: }
0437:
0438: @SuppressWarnings("deprecation")
0439: public final void testMouseDownUp() {
0440:
0441: myTestComp = new MyComponent() {
0442: @Override
0443: public boolean mouseDown(Event evt, int arg1, int arg2) {
0444: synchronized (robot) {
0445: return callback(evt);
0446: }
0447: }
0448:
0449: @Override
0450: public boolean mouseUp(Event evt, int arg1, int arg2) {
0451: synchronized (robot) {
0452: return callback(evt);
0453: }
0454: }
0455: };
0456: int eventId = Event.MOUSE_DOWN;
0457: createFrameAndWait();
0458: robot.setAutoDelay(500);
0459:
0460: Point screenLoc = myTestComp.getLocationOnScreen();
0461: int centerX = myTestComp.getWidth() / 2, centerY = myTestComp
0462: .getHeight() / 2;
0463: screenLoc.translate(centerX, centerY);
0464: robot.mouseMove(screenLoc.x, screenLoc.y);
0465: waitForEvent(new Runnable() {
0466: public void run() {
0467: robot.mousePress(InputEvent.BUTTON1_MASK);
0468: }
0469: }, eventId, waitTime);
0470:
0471: assertNotNull(event);
0472: Event mouseEvt = new Event(myTestComp, 0l, eventId, centerX,
0473: centerY, 0, 0);
0474: mouseEvt.clickCount = 1;
0475: checkOldEvent(mouseEvt);
0476:
0477: eventId = Event.MOUSE_UP;
0478: waitForEvent(new Runnable() {
0479: public void run() {
0480: robot.mouseRelease(InputEvent.BUTTON1_MASK);
0481: }
0482: }, eventId, waitTime);
0483: assertNotNull(event);
0484: mouseEvt.clickCount = 0;
0485: mouseEvt.id = Event.MOUSE_UP;
0486: checkOldEvent(mouseEvt);
0487:
0488: }
0489:
0490: @SuppressWarnings("deprecation")
0491: public final void testMouseEnterExit() {
0492:
0493: myTestComp = new MyComponent() {
0494: @Override
0495: public boolean mouseEnter(Event evt, int arg1, int arg2) {
0496: synchronized (robot) {
0497: return callback(evt);
0498: }
0499: }
0500:
0501: @Override
0502: public boolean mouseExit(Event evt, int arg1, int arg2) {
0503: synchronized (robot) {
0504: return callback(evt);
0505: }
0506: }
0507: };
0508: int eventId = Event.MOUSE_ENTER;
0509: createFrameAndWait();
0510: robot.setAutoDelay(20);
0511:
0512: Point screenLoc = myTestComp.getLocationOnScreen();
0513: Dimension size = myTestComp.getSize();
0514: final int outX = screenLoc.x + size.width + 1;
0515:
0516: screenLoc.translate(size.width / 2, size.height / 2);
0517: final int centerY = screenLoc.y;
0518: final int centerX = screenLoc.x;
0519: final float k = centerY / centerX;
0520:
0521: //mouse enter:
0522: waitForEvent(new Runnable() {
0523: public void run() {
0524: robot.mouseMove(0, 0);
0525: for (int x = 0; x <= centerX; x++) {
0526: robot.mouseMove(x, (int) (k * x));
0527: }
0528: }
0529: }, eventId, waitTime);
0530:
0531: assertNotNull(event);
0532: assertEquals(eventId, event.id);
0533: assertEquals(0, event.modifiers);
0534:
0535: eventId = Event.MOUSE_EXIT;
0536: waitForEvent(new Runnable() {
0537: public void run() {
0538: robot.mousePress(InputEvent.BUTTON3_MASK); //for modifiers test
0539: for (int x = centerX; x <= outX; x++) {
0540: robot.mouseMove(x, centerY);
0541: }
0542: robot.mouseRelease(InputEvent.BUTTON3_MASK); //for modifiers test
0543: }
0544: }, eventId, waitTime);
0545:
0546: assertNotNull(event);
0547: assertEquals(eventId, event.id);
0548: assertEquals(Event.META_MASK, event.modifiers);
0549:
0550: }
0551:
0552: @SuppressWarnings("deprecation")
0553: public final void testMouseDragMove() {
0554: int eventId = Event.MOUSE_MOVE;
0555: myTestComp = new MyComponent() {
0556: @Override
0557: public boolean mouseMove(Event evt, int arg1, int arg2) {
0558: synchronized (robot) {
0559: return callback(evt);
0560: }
0561: }
0562:
0563: @Override
0564: public boolean mouseDrag(Event evt, int arg1, int arg2) {
0565: synchronized (robot) {
0566: return callback(evt);
0567: }
0568: }
0569:
0570: };
0571: createFrameAndWait();
0572: robot.setAutoDelay(300);
0573:
0574: Point screenLoc = myTestComp.getLocationOnScreen(), absLoc = new Point();
0575: absLoc.setLocation(screenLoc);
0576: Dimension size = myTestComp.getSize();
0577: int dx = size.width / 3, dy = size.height / 3;
0578: absLoc.translate(dx, dy);
0579: final Point pos = absLoc;
0580: waitForEvent(new Runnable() {
0581: public void run() {
0582: robot.mouseMove(pos.x, pos.y);
0583: }
0584: }, eventId, waitTime);
0585: assertNotNull(event);
0586: Event mouseEvt = new Event(myTestComp, 0l, eventId, dx, dy, 0,
0587: 0);
0588: checkOldEvent(mouseEvt);
0589: absLoc.translate(3, 3);
0590: final Point dragPos = absLoc;
0591: eventId = Event.MOUSE_DRAG;
0592: waitForEvent(new Runnable() {
0593: public void run() {
0594: robot.mousePress(InputEvent.BUTTON1_MASK
0595: | InputEvent.BUTTON3_MASK); //for drag test
0596: robot.mouseMove(dragPos.x, dragPos.y);
0597: robot.mouseRelease(InputEvent.BUTTON1_MASK
0598: | InputEvent.BUTTON3_MASK); //for drag test
0599: }
0600: }, eventId, waitTime);
0601: assertNotNull(event);
0602: mouseEvt.id = eventId;
0603: mouseEvt.x = absLoc.x - screenLoc.x;
0604: mouseEvt.y = absLoc.y - screenLoc.y;
0605: mouseEvt.modifiers = InputEvent.BUTTON3_MASK;
0606: checkOldEvent(mouseEvt);
0607:
0608: }
0609:
0610: public final void testGotLostFocus() {
0611: waitFocus();
0612: //LOST_FOCUS
0613: int eventId = Event.LOST_FOCUS;
0614: waitForEvent(new Runnable() {
0615: public void run() {
0616: frame.requestFocus();
0617: }
0618: }, eventId, waitTime);
0619: assertNotNull(event);
0620: checkOldEvent(new Event(myTestComp, eventId, null));
0621:
0622: }
0623:
0624: public final void testKeyDownUp() {
0625: waitFocus();
0626: final int keyCode = KeyEvent.VK_A;
0627: int oldKey = 'a';
0628: // KEY_PRESS:
0629: int eventId = Event.KEY_PRESS;
0630: waitForEvent(new Runnable() {
0631: public void run() {
0632: robot.keyPress(keyCode);
0633: }
0634: }, eventId, waitTime);
0635: assertNotNull(event);
0636: checkOldEvent(new Event(myTestComp, 0l, eventId, 0, 0, oldKey,
0637: 0));
0638:
0639: // KEY_RELEASE:
0640: eventId = Event.KEY_RELEASE;
0641: waitForEvent(new Runnable() {
0642: public void run() {
0643: robot.keyRelease(keyCode);
0644: }
0645: }, eventId, waitTime);
0646: assertNotNull(event);
0647: checkOldEvent(new Event(myTestComp, 0l, eventId, 0, 0, oldKey,
0648: 0));
0649:
0650: }
0651:
0652: private void waitFocus() {
0653: myTestComp = new MyComponent();
0654: int eventId = Event.GOT_FOCUS;
0655: myTestComp.setFocusable(true);
0656: frame = new Frame();
0657:
0658: myTestComp.setBounds(20, 20, 40, 30);
0659: frame.setBounds(0, 0, 150, 100);
0660:
0661: frame.add(myTestComp);
0662: createRobot();
0663:
0664: robot.setAutoDelay(300);
0665: // GOT_FOCUS:
0666: waitForEvent(new Runnable() {
0667: public void run() {
0668: frame.setVisible(true);
0669: }
0670: }, eventId, waitTime);
0671: assertNotNull(event);
0672: checkOldEvent(new Event(myTestComp, eventId, null));
0673: }
0674:
0675: public final void testKeyActionRelease() {
0676: waitFocus();
0677: final int keyCode = KeyEvent.VK_PAGE_UP;
0678: int oldKey = Event.PGUP;
0679: // KEY_ACTION:
0680: int eventId = Event.KEY_ACTION;
0681: waitForEvent(new Runnable() {
0682: public void run() {
0683: robot.keyPress(keyCode);
0684: }
0685: }, eventId, waitTime);
0686: assertNotNull(event);
0687: checkOldEvent(new Event(myTestComp, 0l, eventId, 0, 0, oldKey,
0688: 0));
0689: // KEY_ACTION_RELEASE:
0690: eventId = Event.KEY_ACTION_RELEASE;
0691: waitForEvent(new Runnable() {
0692: public void run() {
0693: robot.keyRelease(keyCode);
0694: }
0695: }, eventId, waitTime);
0696: assertNotNull(event);
0697: checkOldEvent(new Event(myTestComp, 0l, eventId, 0, 0, oldKey,
0698: 0));
0699: }
0700:
0701: public final void testWindowDestroy() {
0702: int eventId = Event.WINDOW_DESTROY;
0703: createRobot();
0704: robot.setAutoDelay(250);
0705: assertNull(frame);
0706: frame = new MyFrame();
0707:
0708: frame.setBounds(0, 0, 100, 100);
0709:
0710: //wait for GOT_FOCUS:
0711: event = waitForEvent(new Runnable() {
0712: public void run() {
0713: frame.setVisible(true);
0714: frame.toFront();
0715: }
0716: }, Event.GOT_FOCUS, waitTime);
0717: assertNotNull(event);
0718: assertEquals(Event.GOT_FOCUS, event.id);
0719:
0720: event = waitForEvent(new Runnable() {
0721: public void run() {
0722:
0723: // close window by pressing <ALT> + <F4>
0724: robot.keyPress(KeyEvent.VK_ALT);
0725: robot.keyPress(KeyEvent.VK_F4);
0726: robot.keyRelease(KeyEvent.VK_F4);
0727: robot.keyRelease(KeyEvent.VK_ALT);
0728:
0729: }
0730: }, eventId, waitTime);
0731: assertNotNull(event);
0732: assertEquals(eventId, event.id);
0733: checkOldEvent(new Event(frame, eventId, null));
0734:
0735: }
0736:
0737: public final void testWindowIconify() {
0738: int eventId = Event.WINDOW_ICONIFY;
0739: createRobot();
0740: robot.setAutoDelay(250);
0741: assertNull(frame);
0742: frame = new MyFrame();
0743:
0744: frame.setBounds(0, 0, 200, 200);
0745: waitShowWindow(robot, frame);
0746:
0747: event = waitForEvent(new Runnable() {
0748: public void run() {
0749: frame.setState(Frame.ICONIFIED);
0750: }
0751: }, eventId, waitTime);
0752:
0753: assertNotNull(event);
0754: checkOldEvent(new Event(frame, eventId, null));
0755: //must deiconify to become on top of other windows
0756: eventId = Event.WINDOW_DEICONIFY;
0757:
0758: waitForEvent(new Runnable() {
0759: public void run() {
0760: frame.setState(Frame.NORMAL);
0761: }
0762: }, eventId, waitTime);
0763: assertNotNull(event);
0764: checkOldEvent(new Event(frame, eventId, null));
0765:
0766: }
0767:
0768: public final void testWindowMove() {
0769: createRobot();
0770: int eventId = Event.WINDOW_MOVED;
0771: robot.setAutoDelay(250);
0772: assertNull(frame);
0773: frame = new MyFrame();
0774:
0775: frame.setBounds(0, 0, 200, 200);
0776: waitShowWindow(robot, frame);
0777: final int dx = frame.getWidth() / 2;
0778: final int dy = frame.getInsets().top / 2;
0779: final int x = frame.getX() + dx;
0780: final int y = frame.getY() + dy;
0781: waitForEvent(new Runnable() {
0782: public void run() {
0783: robot.mouseMove(x, y);
0784: robot.mousePress(InputEvent.BUTTON1_MASK);
0785: robot.mouseMove(x + 15, y + 15);
0786: robot.mouseRelease(InputEvent.BUTTON1_MASK);
0787: }
0788: }, eventId, waitTime);
0789:
0790: assertNotNull(event);
0791: checkOldEvent(new Event(frame, 0l, eventId, frame.getX(), frame
0792: .getY(), 0, 0));
0793: }
0794:
0795: /**
0796: * Make some action(passed in runnable) on the current thread and then wait
0797: * on a lock until listener is called or a specified amount of time has
0798: * elapsed
0799: *
0800: * @param runnable
0801: * method run() of this object will be called first
0802: * @param eventId
0803: * id(type) of event to wait for
0804: * @param waitTime
0805: * the maximum time to wait
0806: */
0807: private Event waitForEvent(Runnable runnable, int eventId,
0808: int waitTime) {
0809: int timeout = 100;
0810: for (int n = 0; n < nRetries; n++) {
0811: int time = 0;
0812: event = null;
0813:
0814: putEvent(eventId, null); //listener wasn't called
0815: runnable.run();
0816: synchronized (robot) {
0817:
0818: event = null;
0819: //runnable.run();
0820: while (time < waitTime) {
0821: try {
0822: event = getEvent(eventId);
0823: if (event != null) {
0824: return event;
0825: }
0826: robot.wait(timeout);
0827: time += timeout;
0828:
0829: } catch (InterruptedException e) {
0830: // TODO Auto-generated catch block
0831: e.printStackTrace();
0832: }
0833: }
0834: }
0835: }
0836: return event;
0837: }
0838:
0839: private void waitShowWindow(Robot robot, Component comp) {
0840: assertNotNull(robot);
0841: assertNotNull(comp);
0842: paintFlag = false;
0843: comp.setVisible(true);
0844: while (!paintFlag) {
0845: Thread.yield();
0846: }
0847: // Point center = comp.getLocation();
0848: // Component parent = comp;
0849: // //get absolute location before the component is shown on screen
0850: // while (parent != null && !(parent instanceof Window)) {
0851: // parent = parent.getParent();
0852: // Point parentLoc = parent.getLocation();
0853: // center.translate(parentLoc.x, parentLoc.y);
0854: // }
0855: // Dimension size = comp.getSize();
0856: // if (comp instanceof Window) {
0857: // Window w = (Window) comp;
0858: // Insets insets = w.getInsets();
0859: // center.translate(insets.left, insets.top);
0860: // size.width -= insets.left + insets.right;
0861: // size.height -= insets.bottom + insets.top;
0862: // }
0863: // center.translate(size.width / 2, size.height / 2);
0864: // //check pixel color before the window is shown:
0865: // Color c = robot.getPixelColor(center.x, center.y);
0866: // Color newColor = new Color((c.getRed() + 16) & 0xff,
0867: // (c.getGreen() + 16) & 0xff, (c.getBlue() + 16) & 0xff);
0868: // comp.setBackground(newColor);
0869: // if (parent instanceof Window) {
0870: // parent.setVisible(true);
0871: // }
0872: // //wait for frame's background to be painted:
0873: // while (! robot.getPixelColor(center.x, center.y).equals(newColor)) {
0874: // robot.delay(25);
0875: // }
0876:
0877: }
0878:
0879: public final void testAddPropertyChangeListener() {
0880: cleanPropertyFields();
0881:
0882: tc.addPropertyChangeListener(propListener);
0883: PropertyChangeListener[] propListeners = tc
0884: .getPropertyChangeListeners();
0885: assertEquals(1, propListeners.length);
0886: assertSame(propListener, propListeners[0]);
0887:
0888: String name = "Test Component";
0889: tc.setName(name);
0890: checkPropertyFields("name", tc, name);
0891:
0892: cleanPropertyFields();
0893: ComponentOrientation orientation = ComponentOrientation.LEFT_TO_RIGHT;
0894: tc.setComponentOrientation(orientation);
0895: checkPropertyFields("componentOrientation", tc, orientation);
0896:
0897: Color color = Color.BLUE;
0898: cleanPropertyFields();
0899: tc.setBackground(color);
0900: checkPropertyFields("background", tc, color);
0901:
0902: cleanPropertyFields();
0903: tc.setFocusable(false);
0904: checkPropertyFields("focusable", tc, new Boolean(false));
0905:
0906: cleanPropertyFields();
0907: tc.setFocusTraversalKeysEnabled(false);
0908: checkPropertyFields("focusTraversalKeysEnabled", tc,
0909: new Boolean(false));
0910:
0911: cleanPropertyFields();
0912: Set<AWTKeyStroke> keys = Collections.emptySet();
0913: tc.setFocusTraversalKeys(
0914: KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, keys);
0915: checkPropertyFields("upCycleFocusTraversalKeys", tc, keys);
0916: assertNull(oldValue);
0917: keys = new HashSet<AWTKeyStroke>();
0918: keys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ESCAPE,
0919: InputEvent.CTRL_DOWN_MASK));
0920: cleanPropertyFields();
0921: tc.setFocusTraversalKeys(
0922: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys);
0923: checkPropertyFields("forwardFocusTraversalKeys", tc, keys);
0924:
0925: cleanPropertyFields();
0926: keys.clear();
0927: keys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
0928: tc.setFocusTraversalKeys(
0929: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys);
0930: checkPropertyFields("backwardFocusTraversalKeys", tc, keys);
0931:
0932: cleanPropertyFields();
0933: keys.clear();
0934: keys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_F12,
0935: InputEvent.ALT_DOWN_MASK));
0936: tc.setFocusTraversalKeys(
0937: KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, keys);
0938: checkPropertyFields("upCycleFocusTraversalKeys", tc, keys);
0939:
0940: cleanPropertyFields();
0941: tc.setFont(null);
0942: checkPropertyFields("font", tc, null);
0943:
0944: cleanPropertyFields();
0945: color = Color.RED;
0946: tc.setForeground(color);
0947: checkPropertyFields("foreground", tc, color);
0948:
0949: cleanPropertyFields();
0950: tc.setLocale(null);
0951: checkPropertyFields("locale", tc, null);
0952:
0953: cleanPropertyFields();
0954: Dimension size = new Dimension(100, 200);
0955: tc.setPreferredSize(size);
0956: checkPropertyFields("preferredSize", tc, size);
0957:
0958: cleanPropertyFields();
0959: tc.setMinimumSize(size);
0960: checkPropertyFields("minimumSize", tc, size);
0961:
0962: cleanPropertyFields();
0963: tc.setMaximumSize(size);
0964: checkPropertyFields("maximumSize", tc, size);
0965: }
0966:
0967: private void checkPropertyFields(String propName, Object source,
0968: Object newVal) {
0969: assertTrue(listenerCalled);
0970: assertEquals(propName, this .propName);
0971: assertSame(source, src);
0972: assertEquals(newVal, newValue);
0973: if (newVal != null) {
0974: assertFalse(newVal.equals(oldValue));
0975: }
0976: }
0977:
0978: private void cleanPropertyFields() {
0979: listenerCalled = false;
0980: propName = null;
0981: oldValue = newValue = src = null;
0982: }
0983:
0984: private void checkOldEvent(Event evt) {
0985: assertNotNull(event);
0986: int id = evt.id;
0987: assertEquals(id, event.id);
0988: assertSame(evt.target, event.target);
0989: //for mouse events fields x, y, modifiers and clickCount(only MousePress) are valid:
0990: if (id >= Event.MOUSE_DOWN && id <= Event.MOUSE_DRAG) {
0991: checkOldEventModXY(evt);
0992: assertEquals(evt.clickCount,
0993: id == Event.MOUSE_DOWN ? event.clickCount : 0);
0994:
0995: }
0996: //only arg and modifiers(for action only) are valid for these events:
0997: if (id == Event.ACTION_EVENT
0998: || id == Event.LIST_SELECT
0999: || id == Event.LIST_DESELECT
1000: || (id >= Event.SCROLL_LINE_UP && id <= Event.SCROLL_END)) {
1001: assertSame(evt.arg, event.arg);
1002: if (id == Event.ACTION_EVENT) {
1003: assertEquals(evt.modifiers, event.modifiers);
1004: }
1005: }
1006: //x, y, key, modifiers are valid for key events
1007: if (id >= Event.KEY_PRESS && id <= Event.KEY_ACTION_RELEASE) {
1008: checkOldEventModXY(evt);
1009: assertEquals(evt.key, event.key);
1010: }
1011: //x, y are valid for WINDOW_MOVED events
1012: if (id == Event.WINDOW_MOVED) {
1013: checkOldEventXY(evt);
1014: }
1015: }
1016:
1017: private void checkOldEventModXY(Event evt) {
1018: checkOldEventXY(evt);
1019: assertEquals(evt.modifiers, event.modifiers);
1020: }
1021:
1022: private void checkOldEventXY(Event evt) {
1023: assertEquals(evt.x, event.x);
1024: assertEquals(evt.y, event.y);
1025: }
1026:
1027: public final void testFirePropertyChangeStringBooleanBoolean() {
1028: String propName = "booleanProp";
1029: tc.addPropertyChangeListener(propName, propListener);
1030: cleanPropertyFields();
1031: tc.firePropertyChange(propName, false, true);
1032: assertTrue(listenerCalled);
1033: assertEquals(propName, this .propName);
1034: assertSame(tc, src);
1035: assertSame(Boolean.TRUE, newValue);
1036: assertSame(Boolean.FALSE, oldValue);
1037: }
1038:
1039: @SuppressWarnings("deprecation")
1040: public final void testBounds() {
1041: Component comp = new SimpleComponent() {
1042: @Override
1043: public Rectangle bounds() {
1044: methodCalled = true;
1045: return super .bounds();
1046: }
1047: };
1048: Rectangle r = new Rectangle(10, 20, 30, 40);
1049: comp.setBounds(r);
1050: assertFalse(methodCalled);
1051: Rectangle r1 = comp.getBounds();
1052: assertTrue(methodCalled);
1053: assertNotSame(r, r1);
1054: assertEquals(r, r1);
1055: }
1056:
1057: @SuppressWarnings("deprecation")
1058: public final void testDisableEnable() {
1059: Component comp = new SimpleComponent() {
1060: @Override
1061: public void disable() {
1062: assertTrue(methodCalled);//called from enable(boolean)
1063: methodCalled = true;
1064: super .disable();
1065: }
1066:
1067: @Override
1068: public void enable(boolean b) {
1069: assertFalse(methodCalled);
1070: methodCalled = true;
1071: super .enable(b);
1072: }
1073:
1074: @Override
1075: public void enable() {
1076: assertTrue(methodCalled);//called from enable(boolean)
1077: methodCalled = true;
1078: super .enable();
1079: }
1080: };
1081:
1082: assertFalse(methodCalled);
1083: assertTrue(comp.isEnabled());
1084: comp.setEnabled(false);
1085: assertTrue(methodCalled);
1086: assertFalse(comp.isEnabled());
1087: methodCalled = false;
1088: comp.setEnabled(true);
1089: assertTrue(methodCalled);
1090: assertTrue(comp.isEnabled());
1091: }
1092:
1093: @SuppressWarnings("deprecation")
1094: public final void testHideShow() {
1095: Component comp = new SimpleComponent() {
1096: @Override
1097: public void hide() {
1098: assertTrue(methodCalled);//called from enable(boolean)
1099: methodCalled = true;
1100: super .hide();
1101: }
1102:
1103: @Override
1104: public void show(boolean b) {
1105: assertFalse(methodCalled);
1106: methodCalled = true;
1107: super .show(b);
1108: }
1109:
1110: @Override
1111: public void show() {
1112: assertTrue(methodCalled);//called from enable(boolean)
1113: methodCalled = true;
1114: super .show();
1115: }
1116: };
1117:
1118: assertFalse(methodCalled);
1119: assertTrue(comp.isVisible());
1120: comp.setVisible(false);
1121: assertTrue(methodCalled);
1122: assertFalse(comp.isVisible());
1123: methodCalled = false;
1124: comp.setVisible(true);
1125: assertTrue(methodCalled);
1126: assertTrue(comp.isVisible());
1127: }
1128:
1129: @SuppressWarnings("deprecation")
1130: public final void testInside() {
1131: Component comp = new SimpleComponent() {
1132: @Override
1133: public boolean inside(int x, int y) {
1134: methodCalled = true;
1135: return super .inside(x, y);
1136: }
1137: };
1138: Point p = new Point(-1, -1);
1139: comp.setBounds(0, 5, 10, 15);
1140: assertFalse(methodCalled);
1141: assertFalse(comp.contains(p));
1142: assertTrue(methodCalled);
1143: p.setLocation(8, 14);
1144: methodCalled = false;
1145: assertTrue(comp.contains(p));
1146: assertTrue(methodCalled);
1147: }
1148:
1149: @SuppressWarnings("deprecation")
1150: public final void testIsFocusTraversable() {
1151: Component comp = new SimpleComponent() {
1152: @Override
1153: public boolean isFocusTraversable() {
1154: methodCalled = true;
1155: return super .isFocusTraversable();
1156: }
1157: };
1158: assertFalse(methodCalled);
1159: assertTrue(comp.isFocusable());
1160: assertTrue(methodCalled);
1161: }
1162:
1163: @SuppressWarnings("deprecation")
1164: public final void testLayout() {
1165: Component comp = new SimpleComponent() {
1166: @Override
1167: public void layout() {
1168: methodCalled = true;
1169: super .layout();
1170: }
1171: };
1172: assertFalse(methodCalled);
1173: comp.doLayout();
1174: assertTrue(methodCalled);
1175:
1176: }
1177:
1178: @SuppressWarnings("deprecation")
1179: public final void testLocate() {
1180: Component comp = new SimpleComponent() {
1181: @Override
1182: public Component locate(int x, int y) {
1183: methodCalled = true;
1184: return super .locate(x, y);
1185: }
1186: };
1187: comp.setBounds(0, 0, 10, 20);
1188: Point p = new Point(5, 15);
1189: assertFalse(methodCalled);
1190: assertSame(comp, comp.getComponentAt(p));
1191: assertTrue(methodCalled);
1192: p.setLocation(100, 100);
1193: assertNull(comp.getComponentAt(p));
1194:
1195: }
1196:
1197: @SuppressWarnings("deprecation")
1198: public final void testLocation() {
1199: Component comp = new SimpleComponent() {
1200: @Override
1201: public Point location() {
1202: methodCalled = true;
1203: return super .location();
1204: }
1205: };
1206:
1207: Point p = new Point(10, 20);
1208: comp.setLocation(p);
1209: assertFalse(methodCalled);
1210: assertEquals(p, comp.getLocation());
1211: assertTrue(methodCalled);
1212: }
1213:
1214: @SuppressWarnings("deprecation")
1215: public final void testMinimumSize() {
1216: Component comp = new SimpleComponent() {
1217: @Override
1218: public Dimension minimumSize() {
1219: methodCalled = true;
1220: return super .minimumSize();
1221: }
1222: };
1223: Dimension size = new Dimension();
1224: assertFalse(methodCalled);
1225: Dimension minSize = comp.getMinimumSize();
1226: assertTrue(methodCalled);
1227: assertEquals(size, minSize);
1228: size.setSize(10, 15);
1229: comp.setSize(size);
1230: minSize = comp.getMinimumSize();
1231: assertNotSame(size, minSize);
1232: assertEquals(size, minSize);
1233: }
1234:
1235: @SuppressWarnings("deprecation")
1236: public final void testPreferredSize() {
1237: assertEquals(new Dimension(), tc.getPreferredSize());
1238: final Dimension minSize = new Dimension(5, 15);
1239: Component comp = new SimpleComponent() {
1240: @Override
1241: public Dimension preferredSize() {
1242: methodCalled = true;
1243: return super .preferredSize();
1244: }
1245:
1246: @Override
1247: public Dimension minimumSize() {
1248: return minSize;
1249: }
1250: };
1251:
1252: assertFalse(methodCalled);
1253: Dimension prefSize = comp.getPreferredSize();
1254: assertTrue(methodCalled);
1255: assertNotSame(minSize, prefSize);
1256: assertEquals(minSize, prefSize);
1257:
1258: }
1259:
1260: @SuppressWarnings("deprecation")
1261: public final void testSize() {
1262: Component comp = new SimpleComponent() {
1263: @Override
1264: public Dimension size() {
1265: methodCalled = true;
1266: return super .size();
1267: }
1268: };
1269: Dimension size = new Dimension();
1270: assertFalse(methodCalled);
1271: assertEquals(size, comp.getSize());
1272: assertTrue(methodCalled);
1273: size.setSize(10, 15);
1274: comp.setSize(size);
1275: assertEquals(size, comp.getSize());
1276: }
1277:
1278: @SuppressWarnings("deprecation")
1279: public final void testReshape() {
1280: Component comp = new SimpleComponent() {
1281: @Override
1282: public void reshape(int x, int y, int w, int h) {
1283: methodCalled = true;
1284: super .reshape(x, y, w, h);
1285: }
1286: };
1287: Rectangle rect = new Rectangle(5, 6, 7, 8);
1288: assertFalse(methodCalled);
1289: comp.setBounds(rect);
1290: assertTrue(methodCalled);
1291: assertEquals(rect, comp.getBounds());
1292: }
1293:
1294: @SuppressWarnings("deprecation")
1295: public final void testMove() {
1296: Component comp = new MoveResizeComponent() {
1297: @Override
1298: public void move(int x, int y) {
1299: assertFalse(methodCalled);
1300: assertFalse(setBoundsCalled);
1301: assertFalse(reshapeCalled);
1302: methodCalled = true;
1303: super .move(x, y);
1304: }
1305: };
1306: Point p = new Point(5, 6);
1307: comp.setLocation(p);
1308: assertTrue(methodCalled);
1309: assertTrue(setBoundsCalled);
1310: assertTrue(reshapeCalled);
1311: assertEquals(p, comp.getLocation());
1312: }
1313:
1314: @SuppressWarnings("deprecation")
1315: public final void testResizeIntInt() {
1316: Component comp = new MoveResizeComponent() {
1317: @Override
1318: public void resize(int x, int y) {
1319: assertFalse(methodCalled);
1320: assertFalse(setBoundsCalled);
1321: assertFalse(reshapeCalled);
1322: methodCalled = true;
1323: super .resize(x, y);
1324: }
1325: };
1326: comp.setSize(10, 20);
1327: assertTrue(methodCalled);
1328: assertTrue(setBoundsCalled);
1329: assertTrue(reshapeCalled);
1330: assertEquals(new Dimension(10, 20), comp.getSize());
1331: }
1332:
1333: @SuppressWarnings("deprecation")
1334: public final void testResizeDimension() {
1335: Component comp = new SimpleComponent() {
1336: @Override
1337: public void resize(Dimension size) {
1338: assertFalse(methodCalled);
1339: assertFalse(setBoundsCalled);
1340: assertFalse(reshapeCalled);
1341: methodCalled = true;
1342: super .resize(size);
1343: }
1344:
1345: @Override
1346: public void resize(int w, int h) {
1347: assertTrue(methodCalled);
1348: assertTrue(setBoundsCalled);
1349: assertFalse(reshapeCalled);
1350: reshapeCalled = true;
1351: super .resize(w, h);
1352: }
1353:
1354: @Override
1355: public void setSize(int w, int h) {
1356: assertTrue(methodCalled);
1357: assertFalse(setBoundsCalled);
1358: assertFalse(reshapeCalled);
1359: setBoundsCalled = true;
1360: super .setSize(w, h);
1361: }
1362: };
1363: Dimension size = new Dimension(10, 20);
1364: comp.setSize(size);
1365: assertTrue(methodCalled);
1366: assertTrue(setBoundsCalled);
1367: assertTrue(reshapeCalled);
1368: assertEquals(size, comp.getSize());
1369: }
1370:
1371: @SuppressWarnings("deprecation")
1372: public final void testNextFocus() {
1373: Component comp = new SimpleComponent() {
1374: @Override
1375: public void nextFocus() {
1376: methodCalled = true;
1377: super .nextFocus();
1378: }
1379: };
1380:
1381: assertFalse(methodCalled);
1382: comp.transferFocus();
1383: assertTrue(methodCalled);
1384: }
1385:
1386: @SuppressWarnings("deprecation")
1387: public final void testGetPeer() {
1388: frame = new Frame();
1389: Object peer = frame.getPeer();
1390: assertNull(peer);
1391: frame.addNotify();
1392: peer = frame.getPeer();
1393: assertNotNull(peer);
1394: assertTrue(peer instanceof ComponentPeer);
1395: frame.removeNotify();
1396: assertNull(peer = frame.getPeer());
1397: }
1398:
1399: public final void testGetMousePosition() {
1400: assertNotNull(myTestComp);
1401: assertNull(myTestComp.getMousePosition());
1402: createFrameAndWait();
1403: robot.setAutoDelay(100);
1404: Component testComp = new SimpleComponent();
1405: testComp.setBounds(5, 10, 60, 70);
1406: frame.add(testComp);
1407: myTestComp.setBounds(10, 20, 30, 40);
1408: robot.mouseMove(0, 0);
1409: assertNull(myTestComp.getMousePosition());
1410: robot.mouseMove(20, 30);
1411: Point pos = new Point(10, 10);
1412: assertEquals(pos, myTestComp.getMousePosition());
1413: assertNull(testComp.getMousePosition());
1414: robot.mouseMove(45, 65);
1415: pos = new Point(40, 55);
1416: assertEquals(pos, testComp.getMousePosition());
1417: assertNull(myTestComp.getMousePosition());
1418: }
1419: }
|