1
|
|
/*
|
2
|
|
* Angkor Web Framework
|
3
|
|
*
|
4
|
|
* Distributable under LGPL license.
|
5
|
|
* See terms of license at gnu.org.
|
6
|
|
*/
|
7
|
|
|
8
|
|
package com.tirsen.angkor.test.unit;
|
9
|
|
|
10
|
|
import junit.framework.TestCase;
|
11
|
|
|
12
|
|
import java.util.EventListener;
|
13
|
|
import java.util.EventObject;
|
14
|
|
|
15
|
|
import com.tirsen.angkor.*;
|
16
|
|
import com.tirsen.angkor.event.*;
|
17
|
|
|
18
|
|
/**
|
19
|
|
* <!-- $Id: EventQueueTest.java,v 1.1 2002/10/07 19:49:23 tirsen Exp $ -->
|
20
|
|
* <!-- $Author: tirsen $ -->
|
21
|
|
*
|
22
|
|
* @author Jon Tirs´n (tirsen@users.sourceforge.net)
|
23
|
|
* @version $Revision: 1.1 $
|
24
|
|
*/
|
25
|
|
public class EventQueueTest extends TestCase
|
26
|
|
{
|
27
|
1
|
public EventQueueTest(String s)
|
28
|
|
{
|
29
|
1
|
super(s);
|
30
|
|
}
|
31
|
|
|
32
|
|
public class MyEvent extends EventObject
|
33
|
|
{
|
34
|
1
|
public MyEvent(Object source)
|
35
|
|
{
|
36
|
1
|
super(source);
|
37
|
|
}
|
38
|
|
}
|
39
|
|
|
40
|
|
public interface MyEventListener extends EventListener
|
41
|
|
{
|
42
|
|
void eventHappened(MyEvent evt);
|
43
|
|
}
|
44
|
|
|
45
|
|
private class ListenerImpl implements MyEventListener, ActionListener
|
46
|
|
{
|
47
|
|
private EventObject receivedEvent;
|
48
|
|
|
49
|
2
|
public EventObject getReceivedEvent()
|
50
|
|
{
|
51
|
2
|
return receivedEvent;
|
52
|
|
}
|
53
|
|
|
54
|
1
|
public void eventHappened(MyEvent evt)
|
55
|
|
{
|
56
|
1
|
this.receivedEvent = evt;
|
57
|
|
}
|
58
|
|
|
59
|
1
|
public void actionPerformed(ActionEvent evt)
|
60
|
|
{
|
61
|
1
|
this.receivedEvent = evt;
|
62
|
|
}
|
63
|
|
}
|
64
|
|
|
65
|
1
|
public void testSignalEvent() throws Exception
|
66
|
|
{
|
67
|
1
|
ListenerImpl listener = new ListenerImpl();
|
68
|
|
|
69
|
1
|
EventQueue queue = new EventQueue();
|
70
|
|
|
71
|
1
|
Object source = new Object();
|
72
|
1
|
MyEvent my = new MyEvent(source);
|
73
|
1
|
queue.postEvent(MyEventListener.class, listener, my, "eventHappened");
|
74
|
|
|
75
|
1
|
queue.processEvents(null);
|
76
|
|
|
77
|
1
|
assertSame("listener did not receive the correct my event", listener.getReceivedEvent(), my);
|
78
|
|
|
79
|
1
|
ActionEvent action = new ActionEvent(source);
|
80
|
1
|
queue.postEvent(ActionListener.class, listener, action, "actionPerformed");
|
81
|
|
|
82
|
1
|
queue.processEvents(null);
|
83
|
1
|
assertSame("listener did not receive the correct action event", listener.getReceivedEvent(), action);
|
84
|
|
}
|
85
|
|
}
|
86
|
|
|