001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Michael Danilov
019: * @version $Revision$
020: */package java.awt.event;
021:
022: import java.awt.Button;
023:
024: import junit.framework.TestCase;
025:
026: public class InvocationEventTest extends TestCase {
027:
028: InvocationEvent event = null;
029: boolean runnableCalled = false;
030:
031: public final void testInvocationEventObjectRunnable() {
032: Button button = new Button("Button");
033: Runnable runnable = new Runnable() {
034: public void run() {
035: }
036: };
037: event = new InvocationEvent(button, runnable);
038:
039: assertEquals(event.getSource(), button);
040: assertEquals(event.getID(), InvocationEvent.INVOCATION_DEFAULT);
041: assertNull(event.getException());
042: assertFalse(event.getWhen() == 0l);
043: }
044:
045: public final void testInvocationEventObjectRunnableObjectboolean() {
046: Button button = new Button("Button");
047: Runnable runnable = new Runnable() {
048: public void run() {
049: }
050: };
051: event = new InvocationEvent(button, runnable, button, false);
052:
053: assertEquals(event.getSource(), button);
054: assertEquals(event.getID(), InvocationEvent.INVOCATION_DEFAULT);
055: assertNull(event.getException());
056: assertFalse(event.getWhen() == 0l);
057: }
058:
059: public final void testInvocationEventObjectintRunnableObjectboolean() {
060: Button button = new Button("Button");
061: Runnable runnable = new Runnable() {
062: public void run() {
063: }
064: };
065: event = new InvocationEvent(button,
066: InvocationEvent.INVOCATION_DEFAULT, runnable, button,
067: false);
068:
069: assertEquals(event.getSource(), button);
070: assertEquals(event.getID(), InvocationEvent.INVOCATION_DEFAULT);
071: assertNull(event.getException());
072: assertFalse(event.getWhen() == 0l);
073: }
074:
075: public final void testDispatch() {
076: Button button = new Button("Button");
077: Runnable runnable = new Runnable() {
078: public void run() {
079: runnableCalled = true;
080: ((Button) null).setVisible(true);
081: }
082: };
083:
084: event = new InvocationEvent(button, runnable, button, false);
085: boolean exceptionOccured = false;
086: try {
087: event.dispatch();
088: } catch (Throwable t) {
089: exceptionOccured = true;
090: }
091: assertTrue(exceptionOccured);
092:
093: event = new InvocationEvent(button, runnable, button, true);
094: exceptionOccured = false;
095: runnableCalled = false;
096: try {
097: event.dispatch();
098: } catch (Throwable t) {
099: exceptionOccured = true;
100: }
101: assertFalse(exceptionOccured);
102: assertTrue(runnableCalled);
103:
104: event = new InvocationEvent(button, runnable, button, true);
105: runnableCalled = false;
106: synchronized (button) {
107: new Thread() {
108: @Override
109: public void run() {
110: event.dispatch();
111: }
112: }.start();
113: try {
114: button.wait(1000);
115: } catch (InterruptedException e) {
116: e.printStackTrace();
117: }
118: }
119: assertTrue(runnableCalled);
120: }
121:
122: public final void testParamString() {
123: Button button = new Button("Button");
124: Runnable runnable = new Runnable() {
125: public void run() {
126: }
127: };
128: event = new InvocationEvent(button,
129: InvocationEvent.INVOCATION_DEFAULT, runnable, button,
130: false);
131:
132: assertTrue(event
133: .paramString()
134: .startsWith(
135: "INVOCATION_DEFAULT,runnable=java.awt.event.InvocationEventTest$"));
136: assertTrue(event.paramString().indexOf(
137: ",notifier=java.awt.Button[") != -1);
138: assertTrue(event.paramString().indexOf(
139: "],catchExceptions=false,when=") != -1);
140:
141: event = new InvocationEvent(button,
142: InvocationEvent.INVOCATION_DEFAULT + 1024, runnable,
143: button, false);
144: assertTrue(event
145: .paramString()
146: .startsWith(
147: "unknown type,runnable=java.awt.event.InvocationEventTest$"));
148: }
149:
150: }
|