13 |
|
|
14 |
|
public class CopyOnWriteArraySetTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
16 |
< |
junit.textui.TestRunner.run (suite()); |
16 |
> |
junit.textui.TestRunner.run(suite()); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(CopyOnWriteArraySetTest.class); |
51 |
|
|
52 |
|
|
53 |
|
/** |
54 |
< |
* addAll adds each element from the given collection |
54 |
> |
* addAll adds each element from the given collection |
55 |
|
*/ |
56 |
|
public void testAddAll() { |
57 |
|
CopyOnWriteArraySet full = populatedSet(3); |
64 |
|
} |
65 |
|
|
66 |
|
/** |
67 |
< |
* addAll adds each element from the given collection that did not |
67 |
> |
* addAll adds each element from the given collection that did not |
68 |
|
* already exist in the set |
69 |
|
*/ |
70 |
|
public void testAddAll2() { |
78 |
|
} |
79 |
|
|
80 |
|
/** |
81 |
< |
* add will not add the element if it already exists in the set |
81 |
> |
* add will not add the element if it already exists in the set |
82 |
|
*/ |
83 |
|
public void testAdd2() { |
84 |
|
CopyOnWriteArraySet full = populatedSet(3); |
87 |
|
} |
88 |
|
|
89 |
|
/** |
90 |
< |
* add adds the element when it does not exist |
91 |
< |
* in the set |
90 |
> |
* add adds the element when it does not exist |
91 |
> |
* in the set |
92 |
|
*/ |
93 |
|
public void testAdd3() { |
94 |
|
CopyOnWriteArraySet full = populatedSet(3); |
97 |
|
} |
98 |
|
|
99 |
|
/** |
100 |
< |
* clear removes all elements from the set |
100 |
> |
* clear removes all elements from the set |
101 |
|
*/ |
102 |
|
public void testClear() { |
103 |
|
CopyOnWriteArraySet full = populatedSet(3); |
134 |
|
|
135 |
|
|
136 |
|
/** |
137 |
< |
* containsAll returns true for collections with subset of elements |
137 |
> |
* containsAll returns true for collections with subset of elements |
138 |
|
*/ |
139 |
|
public void testContainsAll() { |
140 |
|
CopyOnWriteArraySet full = populatedSet(3); |
147 |
|
} |
148 |
|
|
149 |
|
/** |
150 |
< |
* isEmpty is true when empty, else false |
150 |
> |
* isEmpty is true when empty, else false |
151 |
|
*/ |
152 |
|
public void testIsEmpty() { |
153 |
|
CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
< |
* iterator() returns an iterator containing the elements of the set |
160 |
> |
* iterator() returns an iterator containing the elements of the set |
161 |
|
*/ |
162 |
|
public void testIterator() { |
163 |
|
CopyOnWriteArraySet full = populatedSet(3); |
164 |
|
Iterator i = full.iterator(); |
165 |
|
int j; |
166 |
|
for (j = 0; i.hasNext(); j++) |
167 |
< |
assertEquals(j, ((Integer)i.next()).intValue()); |
167 |
> |
assertEquals(j, i.next()); |
168 |
|
assertEquals(3, j); |
169 |
|
} |
170 |
|
|
171 |
|
/** |
172 |
|
* iterator remove is unsupported |
173 |
|
*/ |
174 |
< |
public void testIteratorRemove () { |
174 |
> |
public void testIteratorRemove() { |
175 |
|
CopyOnWriteArraySet full = populatedSet(3); |
176 |
|
Iterator it = full.iterator(); |
177 |
|
it.next(); |
178 |
|
try { |
179 |
|
it.remove(); |
180 |
|
shouldThrow(); |
181 |
< |
} |
182 |
< |
catch (UnsupportedOperationException success) {} |
181 |
> |
} catch (UnsupportedOperationException success) {} |
182 |
|
} |
183 |
|
|
184 |
|
/** |
194 |
|
|
195 |
|
|
196 |
|
/** |
197 |
< |
* removeAll removes all elements from the given collection |
197 |
> |
* removeAll removes all elements from the given collection |
198 |
|
*/ |
199 |
|
public void testRemoveAll() { |
200 |
|
CopyOnWriteArraySet full = populatedSet(3); |
217 |
|
} |
218 |
|
|
219 |
|
/** |
220 |
< |
* size returns the number of elements |
220 |
> |
* size returns the number of elements |
221 |
|
*/ |
222 |
|
public void testSize() { |
223 |
|
CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); |
227 |
|
} |
228 |
|
|
229 |
|
/** |
230 |
< |
* toArray returns an Object array containing all elements from the set |
230 |
> |
* toArray returns an Object array containing all elements from the set |
231 |
|
*/ |
232 |
|
public void testToArray() { |
233 |
|
CopyOnWriteArraySet full = populatedSet(3); |
234 |
|
Object[] o = full.toArray(); |
235 |
|
assertEquals(3, o.length); |
236 |
< |
assertEquals(0, ((Integer)o[0]).intValue()); |
237 |
< |
assertEquals(1, ((Integer)o[1]).intValue()); |
238 |
< |
assertEquals(2, ((Integer)o[2]).intValue()); |
236 |
> |
assertEquals(0, o[0]); |
237 |
> |
assertEquals(1, o[1]); |
238 |
> |
assertEquals(2, o[2]); |
239 |
|
} |
240 |
|
|
241 |
|
/** |
242 |
< |
* toArray returns an Integer array containing all elements from |
243 |
< |
* the set |
242 |
> |
* toArray returns an Integer array containing all elements from |
243 |
> |
* the set |
244 |
|
*/ |
245 |
|
public void testToArray2() { |
246 |
|
CopyOnWriteArraySet full = populatedSet(3); |
247 |
|
Integer[] i = new Integer[3]; |
248 |
|
i = (Integer[])full.toArray(i); |
249 |
|
assertEquals(3, i.length); |
250 |
< |
assertEquals(0, i[0].intValue()); |
251 |
< |
assertEquals(1, i[1].intValue()); |
252 |
< |
assertEquals(2, i[2].intValue()); |
250 |
> |
assertEquals(0, (int) i[0]); |
251 |
> |
assertEquals(1, (int) i[1]); |
252 |
> |
assertEquals(2, (int) i[2]); |
253 |
|
} |
254 |
|
|
255 |
|
|
264 |
|
c.add("asdadasd"); |
265 |
|
c.toArray(new Long[5]); |
266 |
|
shouldThrow(); |
267 |
< |
} catch (ArrayStoreException e) {} |
267 |
> |
} catch (ArrayStoreException success) {} |
268 |
|
} |
269 |
|
|
270 |
|
/** |
271 |
|
* A deserialized serialized set is equal |
272 |
|
*/ |
273 |
< |
public void testSerialization() { |
273 |
> |
public void testSerialization() throws Exception { |
274 |
|
CopyOnWriteArraySet q = populatedSet(SIZE); |
275 |
|
|
276 |
< |
try { |
277 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
278 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
279 |
< |
out.writeObject(q); |
280 |
< |
out.close(); |
281 |
< |
|
282 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
283 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
284 |
< |
CopyOnWriteArraySet r = (CopyOnWriteArraySet)in.readObject(); |
285 |
< |
assertEquals(q.size(), r.size()); |
286 |
< |
assertTrue(q.equals(r)); |
288 |
< |
assertTrue(r.equals(q)); |
289 |
< |
} catch (Exception e) { |
290 |
< |
unexpectedException(); |
291 |
< |
} |
276 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
277 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
278 |
> |
out.writeObject(q); |
279 |
> |
out.close(); |
280 |
> |
|
281 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
282 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
283 |
> |
CopyOnWriteArraySet r = (CopyOnWriteArraySet)in.readObject(); |
284 |
> |
assertEquals(q.size(), r.size()); |
285 |
> |
assertTrue(q.equals(r)); |
286 |
> |
assertTrue(r.equals(q)); |
287 |
|
} |
288 |
|
|
289 |
|
} |