1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.richclient.command;
17
18 import java.awt.event.ActionEvent;
19 import java.beans.PropertyChangeListener;
20
21 import javax.swing.Action;
22
23 import junit.framework.Assert;
24 import junit.framework.TestCase;
25
26
27
28
29
30
31
32
33
34 public class SwingActionAdapterTests extends TestCase {
35
36
37
38
39 public final void testConstructor() {
40
41 try {
42 new SwingActionAdapter(null);
43 Assert.fail("Should have thrown an IllegalArgumentException");
44 } catch (IllegalArgumentException e) {
45
46 }
47
48
49 MockActionCommand command = new MockActionCommand();
50 command.setActionCommand("bogusActionCommand");
51 command.setCaption("bogusCaption");
52
53 SwingActionAdapter adapter = new SwingActionAdapter(command);
54
55 Assert.assertEquals("bogusActionCommand", adapter.getValue(Action.ACTION_COMMAND_KEY));
56 Assert.assertEquals("bogusCaption", adapter.getValue(Action.SHORT_DESCRIPTION));
57
58 command.setCaption("newCaption");
59
60 adapter.update();
61
62 Assert.assertEquals("newCaption", adapter.getValue(Action.SHORT_DESCRIPTION));
63
64 }
65
66
67
68
69 public final void testActionPerformed() {
70
71 MockActionCommand command = new MockActionCommand();
72 SwingActionAdapter adapter = new SwingActionAdapter(command);
73 adapter.actionPerformed(new ActionEvent(command, 1, "bogus"));
74
75 Assert.assertEquals(1, command.getActionPerformedCount());
76
77 }
78
79 private class MockActionCommand extends ActionCommand {
80
81 private int actionPerformedCount;
82 private PropertyChangeListener enabledListener;
83 private PropertyChangeListener propertyChangeListener;
84
85
86
87
88 protected void doExecuteCommand() {
89 this.actionPerformedCount++;
90 }
91
92
93
94
95 public void addEnabledListener(PropertyChangeListener listener) {
96 this.enabledListener = listener;
97 }
98
99
100
101
102
103 public int getActionPerformedCount() {
104 return this.actionPerformedCount;
105 }
106
107 }
108
109 }