1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.richclient.command.support;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.springframework.richclient.command.AbstractCommand;
22 import org.springframework.richclient.command.AbstractCommandRegistryTests;
23 import org.springframework.richclient.command.ActionCommand;
24 import org.springframework.richclient.command.ActionCommandExecutor;
25 import org.springframework.richclient.command.CommandGroup;
26 import org.springframework.richclient.command.CommandNotOfRequiredTypeException;
27 import org.springframework.richclient.command.CommandRegistry;
28 import org.springframework.richclient.command.CommandRegistryListener;
29
30
31
32
33
34
35
36 public class DefaultCommandRegistryTests extends AbstractCommandRegistryTests {
37
38
39
40
41 protected CommandRegistry getCommandRegistry() {
42 return new DefaultCommandRegistry();
43 }
44
45 public void testConstructor() {
46 DefaultCommandRegistry registry = new DefaultCommandRegistry();
47 assertNull("parent must be null", registry.getParent());
48
49 TestCommandRegistry parent = new TestCommandRegistry();
50 registry = new DefaultCommandRegistry(parent);
51 assertEquals("parent not set", parent, registry.getParent());
52 assertEquals("registry not added to parent", 1, parent.addedListeners.size());
53 assertTrue("registry not added to parent", parent.addedListeners.contains(registry));
54 }
55
56 public void testSetParent() {
57 TestCommandRegistry parent = new TestCommandRegistry();
58 TestCommandRegistry parent2 = new TestCommandRegistry();
59
60 DefaultCommandRegistry registry = new DefaultCommandRegistry(parent);
61
62 registry.setParent(parent2);
63
64 assertEquals("parent not set", parent2, registry.getParent());
65 assertEquals("registry not removed from parent", 1, parent.removedListeners.size());
66 assertTrue("registry not removed from parent", parent.removedListeners.contains(registry));
67 assertEquals("registry not added to parent", 1, parent2.addedListeners.size());
68 assertTrue("registry not added to parent", parent2.addedListeners.contains(registry));
69
70
71 registry.setParent(parent2);
72 assertEquals("registry added twice to same parent", 1, parent2.addedListeners.size());
73 assertTrue("registry removed from same parent", parent2.removedListeners.isEmpty());
74
75 parent2.reset();
76
77
78 registry.setParent(null);
79 assertNull("parent not set to null", registry.getParent());
80 assertEquals("registry not removed from parent", 1, parent2.removedListeners.size());
81 }
82
83 private static class TestCommandRegistry implements CommandRegistry {
84 private List addedListeners = new ArrayList();
85
86 private List removedListeners = new ArrayList();
87
88 public ActionCommand getActionCommand(String commandId) {
89 return null;
90 }
91
92 public CommandGroup getCommandGroup(String groupId) {
93 return null;
94 }
95
96 public boolean containsActionCommand(String commandId) {
97 return false;
98 }
99
100 public boolean containsCommandGroup(String groupId) {
101 return false;
102 }
103
104 public void registerCommand(AbstractCommand command) {
105 }
106
107 public void setTargetableActionCommandExecutor(String targetableCommandId, ActionCommandExecutor commandExecutor) {
108 }
109
110 public void addCommandRegistryListener(CommandRegistryListener l) {
111 addedListeners.add(l);
112 }
113
114 public void removeCommandRegistryListener(CommandRegistryListener l) {
115 removedListeners.add(l);
116 }
117
118 public void reset() {
119 addedListeners.clear();
120 removedListeners.clear();
121 }
122
123
124
125
126 public boolean containsCommand(String commandId) {
127 return false;
128 }
129
130
131
132
133 public Object getCommand(String commandId) {
134 return null;
135 }
136
137
138
139
140 public Object getCommand(String commandId, Class requiredType) throws CommandNotOfRequiredTypeException {
141 return null;
142 }
143
144
145
146
147 public Class getType(String commandId) {
148 return null;
149 }
150
151
152
153
154 public boolean isTypeMatch(String commandId, Class targetType) {
155 return false;
156 }
157
158 }
159
160 }