1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: TestSetModel.java,v 1.6 2002/09/12 19:09:35 ludovicc Exp $
37 */
38 package test.model.collection;
39
40
41 import java.util.ArrayList;
42 import java.util.HashSet;
43 import java.util.LinkedList;
44 import java.util.List;
45 import java.util.Set;
46 import junit.framework.TestCase;
47 import org.scopemvc.core.ModelChangeEvent;
48 import org.scopemvc.core.ModelChangeListener;
49 import org.scopemvc.model.collection.ListModel;
50 import org.scopemvc.model.collection.SetModel;
51 import test.model.basic.BasicTestModel;
52
53 /***
54 * <P>
55 *
56 * </P>
57 *
58 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A>
59 * @created 05 September 2002
60 * @version $Revision: 1.6 $
61 */
62 public final class TestSetModel extends TestCase implements ModelChangeListener {
63
64 private SetModel setModel;
65 private BasicTestModel model, submodel;
66 private Set set;
67
68 private boolean modelChanged;
69
70
71 /***
72 * Constructor for the TestSetModel object
73 *
74 * @param inName Name of the test
75 */
76 public TestSetModel(String inName) {
77 super(inName);
78 }
79
80
81 /***
82 * A unit test for JUnit
83 *
84 * @throws Exception Any abnormal exception
85 */
86 public void testDefaultConstructor() throws Exception {
87 SetModel m = new SetModel();
88 assertTrue(m.getSize() == 0);
89 }
90
91
92 /***
93 * A unit test for JUnit
94 *
95 * @throws Exception Any abnormal exception
96 */
97 public void testBooleanConstructor1() throws Exception {
98 SetModel m = new SetModel(false);
99 assertTrue(m.getSize() == 0);
100 }
101
102
103 /***
104 * A unit test for JUnit
105 *
106 * @throws Exception Any abnormal exception
107 */
108 public void testBooleanConstructor2() throws Exception {
109 SetModel m = new SetModel(true);
110 assertTrue(m.getSize() == 0);
111 }
112
113
114 /***
115 * A unit test for JUnit
116 *
117 * @throws Exception Any abnormal exception
118 */
119 public void testSetConstructor() throws Exception {
120 SetModel m = new SetModel(set);
121 assertTrue(m.getSize() == set.size());
122 assertTrue(m.containsAll(set));
123 }
124
125
126 /***
127 * A unit test for JUnit
128 *
129 * @throws Exception Any abnormal exception
130 */
131 public void testBooleanSetConstructor1() throws Exception {
132 SetModel m = new SetModel(true, set);
133 assertTrue(m.getSize() == set.size());
134 assertTrue(m.containsAll(set));
135 }
136
137
138 /***
139 * A unit test for JUnit
140 *
141 * @throws Exception Any abnormal exception
142 */
143 public void testBooleanSetConstructor2() throws Exception {
144 SetModel m = new SetModel(false, set);
145 assertTrue(m.getSize() == set.size());
146 assertTrue(m.containsAll(set));
147 }
148
149
150 /***
151 * A unit test for JUnit
152 *
153 * @throws Exception Any abnormal exception
154 */
155 public void testSetModelSetSet() throws Exception {
156 Set o = new HashSet();
157 o.add(new Integer(99));
158 setModel.addModelChangeListener(this);
159 modelChanged = false;
160
161 setModel.setSet(o);
162 assertTrue(setModel.getSize() == 1);
163 assertTrue(setModel.containsAll(o));
164 assertTrue(modelChanged);
165 }
166
167
168 /***
169 * A unit test for JUnit
170 *
171 * @throws Exception Any abnormal exception
172 */
173 public void testSetModelChangeEventPropagation1() throws Exception {
174 setModel.addModelChangeListener(this);
175
176 modelChanged = false;
177 setModel.add("new");
178 assertTrue(modelChanged);
179 }
180
181
182 /***
183 * A unit test for JUnit
184 *
185 * @throws Exception Any abnormal exception
186 */
187 public void testSetModelChangeEventPropagation2() throws Exception {
188 setModel.addModelChangeListener(this);
189
190 modelChanged = false;
191 setModel.add(model);
192 assertTrue(modelChanged);
193
194 modelChanged = false;
195 model.setName("new");
196 assertTrue(modelChanged);
197
198 modelChanged = false;
199 setModel.remove(model);
200 assertTrue(modelChanged);
201 }
202
203
204 /***
205 * A unit test for JUnit
206 *
207 * @throws Exception Any abnormal exception
208 */
209 public void testSetModelChangeEventPropagation3() throws Exception {
210 setModel.addModelChangeListener(this);
211
212 modelChanged = false;
213 List l = new LinkedList();
214 l.add(model);
215 setModel.addAll(l);
216 assertTrue(modelChanged);
217 }
218
219
220 /***
221 * A unit test for JUnit
222 *
223 * @throws Exception Any abnormal exception
224 */
225 public void testSetModelChangeEventPropagation4() throws Exception {
226 setModel.addModelChangeListener(this);
227
228 setModel.add(model);
229 setModel.add(submodel);
230
231 modelChanged = false;
232 List l = new LinkedList();
233 l.add(model);
234 setModel.retainAll(l);
235 assertTrue(modelChanged);
236 }
237
238
239 /***
240 * A unit test for JUnit
241 *
242 * @throws Exception Any abnormal exception
243 */
244 public void testSetModelChangeEventPropagation5() throws Exception {
245 setModel.addModelChangeListener(this);
246
247 setModel.add(model);
248 setModel.add(submodel);
249
250 modelChanged = false;
251 List l = new LinkedList();
252 l.add(model);
253 setModel.removeAll(l);
254 assertTrue(modelChanged);
255 }
256
257
258 /***
259 * A unit test for JUnit
260 *
261 * @throws Exception Any abnormal exception
262 */
263 public void testSetModelChangeEventPropagation6() throws Exception {
264 setModel.addModelChangeListener(this);
265 setModel.add(model);
266 setModel.add(submodel);
267
268 modelChanged = false;
269 setModel.clear();
270 assertTrue(modelChanged);
271 }
272
273
274 /***
275 * TODO: document the method
276 *
277 * @param inEvent TODO: Describe the Parameter
278 */
279 public void modelChanged(ModelChangeEvent inEvent) {
280 modelChanged = true;
281 }
282
283
284 /***
285 * The JUnit setup method
286 *
287 * @throws Exception Any abnormal exception
288 */
289 protected void setUp() throws Exception {
290 setModel = new SetModel();
291 for (int i = 0; i < 10; ++i) {
292 setModel.add(new Integer(i));
293 }
294
295 model = new BasicTestModel("model");
296 submodel = new BasicTestModel("submodel");
297 model.setSubModel(submodel);
298
299 set = new HashSet();
300 for (int i = 0; i < 10; ++i) {
301 set.add("test" + i);
302 }
303 modelChanged = false;
304 }
305 }
This page was automatically generated by Maven