30 |
|
return a; |
31 |
|
} |
32 |
|
|
33 |
+ |
/** |
34 |
+ |
* Default-constructed set is empty |
35 |
+ |
*/ |
36 |
|
public void testConstructor() { |
37 |
|
CopyOnWriteArraySet a = new CopyOnWriteArraySet(); |
38 |
|
assertTrue(a.isEmpty()); |
39 |
|
} |
40 |
|
|
41 |
+ |
/** |
42 |
+ |
* Collection-constructed list holds all of its elements |
43 |
+ |
*/ |
44 |
|
public void testConstructor3() { |
45 |
|
Integer[] ints = new Integer[SIZE]; |
46 |
|
for (int i = 0; i < SIZE-1; ++i) |
54 |
|
/** |
55 |
|
* addAll correctly adds each element from the given collection |
56 |
|
*/ |
57 |
< |
public void testAddAll(){ |
57 |
> |
public void testAddAll() { |
58 |
|
CopyOnWriteArraySet full = populatedSet(3); |
59 |
|
Vector v = new Vector(); |
60 |
|
v.add(three); |
68 |
|
* addAllAbsent adds each element from the given collection that did not |
69 |
|
* already exist in the List |
70 |
|
*/ |
71 |
< |
public void testAddAll2(){ |
71 |
> |
public void testAddAll2() { |
72 |
|
CopyOnWriteArraySet full = populatedSet(3); |
73 |
|
Vector v = new Vector(); |
74 |
|
v.add(three); |
81 |
|
/** |
82 |
|
* addIfAbsent will not add the element if it already exists in the list |
83 |
|
*/ |
84 |
< |
public void testAdd2(){ |
84 |
> |
public void testAdd2() { |
85 |
|
CopyOnWriteArraySet full = populatedSet(3); |
86 |
|
full.add(one); |
87 |
|
assertEquals(3, full.size()); |
88 |
|
} |
89 |
|
|
90 |
|
/** |
91 |
< |
* addIfAbsent correctly adds the element when it does not exist in the list |
91 |
> |
* addIfAbsent correctly adds the element when it does not exist |
92 |
> |
* in the list |
93 |
|
*/ |
94 |
< |
public void testAdd3(){ |
94 |
> |
public void testAdd3() { |
95 |
|
CopyOnWriteArraySet full = populatedSet(3); |
96 |
|
full.add(three); |
97 |
|
assertTrue(full.contains(three)); |
100 |
|
/** |
101 |
|
* clear correctly removes all elements from the list |
102 |
|
*/ |
103 |
< |
public void testClear(){ |
103 |
> |
public void testClear() { |
104 |
|
CopyOnWriteArraySet full = populatedSet(3); |
105 |
|
full.clear(); |
106 |
|
assertEquals(0, full.size()); |
109 |
|
/** |
110 |
|
* contains returns the correct values |
111 |
|
*/ |
112 |
< |
public void testContains(){ |
112 |
> |
public void testContains() { |
113 |
|
CopyOnWriteArraySet full = populatedSet(3); |
114 |
|
assertTrue(full.contains(one)); |
115 |
|
assertFalse(full.contains(five)); |
116 |
|
} |
117 |
|
|
118 |
+ |
/** |
119 |
+ |
* Sets with equal elements are equal |
120 |
+ |
*/ |
121 |
|
public void testEquals() { |
122 |
|
CopyOnWriteArraySet a = populatedSet(3); |
123 |
|
CopyOnWriteArraySet b = populatedSet(3); |
137 |
|
/** |
138 |
|
* containsAll returns the correct values |
139 |
|
*/ |
140 |
< |
public void testContainsAll(){ |
140 |
> |
public void testContainsAll() { |
141 |
|
CopyOnWriteArraySet full = populatedSet(3); |
142 |
|
Vector v = new Vector(); |
143 |
|
v.add(one); |
150 |
|
/** |
151 |
|
* isEmpty returns the correct values |
152 |
|
*/ |
153 |
< |
public void testIsEmpty(){ |
153 |
> |
public void testIsEmpty() { |
154 |
|
CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); |
155 |
|
CopyOnWriteArraySet full = populatedSet(3); |
156 |
|
assertTrue(empty.isEmpty()); |
160 |
|
/** |
161 |
|
* iterator() returns an iterator containing the elements of the list |
162 |
|
*/ |
163 |
< |
public void testIterator(){ |
163 |
> |
public void testIterator() { |
164 |
|
CopyOnWriteArraySet full = populatedSet(3); |
165 |
|
Iterator i = full.iterator(); |
166 |
|
int j; |
169 |
|
assertEquals(3, j); |
170 |
|
} |
171 |
|
|
172 |
+ |
/** |
173 |
+ |
* iterator remove is unsupported |
174 |
+ |
*/ |
175 |
|
public void testIteratorRemove () { |
176 |
|
CopyOnWriteArraySet full = populatedSet(3); |
177 |
|
Iterator it = full.iterator(); |
178 |
|
it.next(); |
179 |
|
try { |
180 |
|
it.remove(); |
181 |
< |
fail("should throw"); |
181 |
> |
shouldThrow(); |
182 |
|
} |
183 |
|
catch (UnsupportedOperationException success) {} |
184 |
|
} |
185 |
|
|
186 |
< |
public void testToString(){ |
186 |
> |
/** |
187 |
> |
* toString holds toString of elements |
188 |
> |
*/ |
189 |
> |
public void testToString() { |
190 |
|
CopyOnWriteArraySet full = populatedSet(3); |
191 |
|
String s = full.toString(); |
192 |
|
for (int i = 0; i < 3; ++i) { |
198 |
|
/** |
199 |
|
* removeAll correctly removes all elements from the given collection |
200 |
|
*/ |
201 |
< |
public void testRemoveAll(){ |
201 |
> |
public void testRemoveAll() { |
202 |
|
CopyOnWriteArraySet full = populatedSet(3); |
203 |
|
Vector v = new Vector(); |
204 |
|
v.add(one); |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
< |
public void testRemove(){ |
211 |
> |
/** |
212 |
> |
* remove removes an element |
213 |
> |
*/ |
214 |
> |
public void testRemove() { |
215 |
|
CopyOnWriteArraySet full = populatedSet(3); |
216 |
|
full.remove(one); |
217 |
|
assertFalse(full.contains(one)); |
221 |
|
/** |
222 |
|
* size returns the correct values |
223 |
|
*/ |
224 |
< |
public void testSize(){ |
224 |
> |
public void testSize() { |
225 |
|
CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); |
226 |
|
CopyOnWriteArraySet full = populatedSet(3); |
227 |
|
assertEquals(3, full.size()); |
231 |
|
/** |
232 |
|
* toArray returns an Object array containing all elements from the list |
233 |
|
*/ |
234 |
< |
public void testToArray(){ |
234 |
> |
public void testToArray() { |
235 |
|
CopyOnWriteArraySet full = populatedSet(3); |
236 |
|
Object[] o = full.toArray(); |
237 |
|
assertEquals(3, o.length); |
241 |
|
} |
242 |
|
|
243 |
|
/** |
244 |
< |
* toArray returns an Integer array containing all elements from the list |
244 |
> |
* toArray returns an Integer array containing all elements from |
245 |
> |
* the list |
246 |
|
*/ |
247 |
< |
public void testToArray2(){ |
247 |
> |
public void testToArray2() { |
248 |
|
CopyOnWriteArraySet full = populatedSet(3); |
249 |
|
Integer[] i = new Integer[3]; |
250 |
|
i = (Integer[])full.toArray(i); |
255 |
|
} |
256 |
|
|
257 |
|
|
238 |
– |
|
239 |
– |
// Exception tests |
240 |
– |
|
258 |
|
/** |
259 |
< |
* toArray throws an ArrayStoreException when the given array |
260 |
< |
* can not store the objects inside the list |
259 |
> |
* toArray throws an ArrayStoreException when the given array can |
260 |
> |
* not store the objects inside the list |
261 |
|
*/ |
262 |
< |
public void testToArray_ArrayStoreException(){ |
263 |
< |
try{ |
262 |
> |
public void testToArray_ArrayStoreException() { |
263 |
> |
try { |
264 |
|
CopyOnWriteArraySet c = new CopyOnWriteArraySet(); |
265 |
|
c.add("zfasdfsdf"); |
266 |
|
c.add("asdadasd"); |
267 |
|
c.toArray(new Long[5]); |
268 |
< |
fail("Object[] toArray(Object[]) should throw ArrayStoreException"); |
269 |
< |
}catch(ArrayStoreException e){} |
268 |
> |
shouldThrow(); |
269 |
> |
} catch(ArrayStoreException e){} |
270 |
|
} |
271 |
|
|
272 |
+ |
/** |
273 |
+ |
* |
274 |
+ |
*/ |
275 |
|
public void testSerialization() { |
276 |
|
CopyOnWriteArraySet q = populatedSet(SIZE); |
277 |
|
|
288 |
|
assertTrue(q.equals(r)); |
289 |
|
assertTrue(r.equals(q)); |
290 |
|
} catch(Exception e){ |
291 |
< |
e.printStackTrace(); |
272 |
< |
fail("unexpected exception"); |
291 |
> |
unexpectedException(); |
292 |
|
} |
293 |
|
} |
294 |
|
|