20 |
|
|
21 |
|
public class CopyOnWriteArraySetTest extends JSR166TestCase { |
22 |
|
public static void main(String[] args) { |
23 |
< |
junit.textui.TestRunner.run(suite()); |
23 |
> |
main(suite(), args); |
24 |
|
} |
25 |
|
public static Test suite() { |
26 |
|
return new TestSuite(CopyOnWriteArraySetTest.class); |
59 |
|
*/ |
60 |
|
public void testConstructor3() { |
61 |
|
Integer[] ints = new Integer[SIZE]; |
62 |
< |
for (int i = 0; i < SIZE-1; ++i) |
62 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
63 |
|
ints[i] = new Integer(i); |
64 |
|
CopyOnWriteArraySet a = new CopyOnWriteArraySet(Arrays.asList(ints)); |
65 |
|
for (int i = 0; i < SIZE; ++i) |
134 |
|
CopyOnWriteArraySet b = populatedSet(3); |
135 |
|
assertTrue(a.equals(b)); |
136 |
|
assertTrue(b.equals(a)); |
137 |
+ |
assertTrue(a.containsAll(b)); |
138 |
+ |
assertTrue(b.containsAll(a)); |
139 |
|
assertEquals(a.hashCode(), b.hashCode()); |
140 |
+ |
assertEquals(a.size(), b.size()); |
141 |
+ |
|
142 |
|
a.add(m1); |
143 |
|
assertFalse(a.equals(b)); |
144 |
|
assertFalse(b.equals(a)); |
145 |
+ |
assertTrue(a.containsAll(b)); |
146 |
+ |
assertFalse(b.containsAll(a)); |
147 |
|
b.add(m1); |
148 |
|
assertTrue(a.equals(b)); |
149 |
|
assertTrue(b.equals(a)); |
150 |
+ |
assertTrue(a.containsAll(b)); |
151 |
+ |
assertTrue(b.containsAll(a)); |
152 |
+ |
assertEquals(a.hashCode(), b.hashCode()); |
153 |
+ |
|
154 |
+ |
Object x = a.iterator().next(); |
155 |
+ |
a.remove(x); |
156 |
+ |
assertFalse(a.equals(b)); |
157 |
+ |
assertFalse(b.equals(a)); |
158 |
+ |
assertFalse(a.containsAll(b)); |
159 |
+ |
assertTrue(b.containsAll(a)); |
160 |
+ |
a.add(x); |
161 |
+ |
assertTrue(a.equals(b)); |
162 |
+ |
assertTrue(b.equals(a)); |
163 |
+ |
assertTrue(a.containsAll(b)); |
164 |
+ |
assertTrue(b.containsAll(a)); |
165 |
|
assertEquals(a.hashCode(), b.hashCode()); |
166 |
+ |
assertEquals(a.size(), b.size()); |
167 |
+ |
|
168 |
+ |
CopyOnWriteArraySet empty1 = new CopyOnWriteArraySet(Arrays.asList()); |
169 |
+ |
CopyOnWriteArraySet empty2 = new CopyOnWriteArraySet(Arrays.asList()); |
170 |
+ |
assertTrue(empty1.equals(empty1)); |
171 |
+ |
assertTrue(empty1.equals(empty2)); |
172 |
+ |
|
173 |
+ |
assertFalse(empty1.equals(a)); |
174 |
+ |
assertFalse(a.equals(empty1)); |
175 |
+ |
|
176 |
+ |
assertFalse(a.equals(null)); |
177 |
|
} |
178 |
|
|
179 |
|
/** |
181 |
|
*/ |
182 |
|
public void testContainsAll() { |
183 |
|
Collection full = populatedSet(3); |
184 |
+ |
assertTrue(full.containsAll(full)); |
185 |
|
assertTrue(full.containsAll(Arrays.asList())); |
186 |
|
assertTrue(full.containsAll(Arrays.asList(one))); |
187 |
|
assertTrue(full.containsAll(Arrays.asList(one, two))); |
188 |
|
assertFalse(full.containsAll(Arrays.asList(one, two, six))); |
189 |
|
assertFalse(full.containsAll(Arrays.asList(six))); |
190 |
+ |
|
191 |
+ |
CopyOnWriteArraySet empty1 = new CopyOnWriteArraySet(Arrays.asList()); |
192 |
+ |
CopyOnWriteArraySet empty2 = new CopyOnWriteArraySet(Arrays.asList()); |
193 |
+ |
assertTrue(empty1.containsAll(empty2)); |
194 |
+ |
assertTrue(empty1.containsAll(empty1)); |
195 |
+ |
assertFalse(empty1.containsAll(full)); |
196 |
+ |
assertTrue(full.containsAll(empty1)); |
197 |
+ |
|
198 |
+ |
try { |
199 |
+ |
full.containsAll(null); |
200 |
+ |
shouldThrow(); |
201 |
+ |
} catch (NullPointerException success) {} |
202 |
|
} |
203 |
|
|
204 |
|
/** |
224 |
|
Integer[] elements = new Integer[SIZE]; |
225 |
|
for (int i = 0; i < SIZE; i++) |
226 |
|
elements[i] = i; |
227 |
< |
Collections.shuffle(Arrays.asList(elements)); |
227 |
> |
shuffle(elements); |
228 |
|
Collection<Integer> full = populatedSet(elements); |
229 |
|
|
230 |
|
Iterator it = full.iterator(); |
311 |
|
Integer[] elements = new Integer[SIZE]; |
312 |
|
for (int i = 0; i < SIZE; i++) |
313 |
|
elements[i] = i; |
314 |
< |
Collections.shuffle(Arrays.asList(elements)); |
314 |
> |
shuffle(elements); |
315 |
|
Collection<Integer> full = populatedSet(elements); |
316 |
|
|
317 |
|
assertTrue(Arrays.equals(elements, full.toArray())); |
329 |
|
a = new Integer[0]; |
330 |
|
assertSame(a, empty.toArray(a)); |
331 |
|
|
332 |
< |
a = new Integer[SIZE/2]; |
332 |
> |
a = new Integer[SIZE / 2]; |
333 |
|
Arrays.fill(a, 42); |
334 |
|
assertSame(a, empty.toArray(a)); |
335 |
|
assertNull(a[0]); |
339 |
|
Integer[] elements = new Integer[SIZE]; |
340 |
|
for (int i = 0; i < SIZE; i++) |
341 |
|
elements[i] = i; |
342 |
< |
Collections.shuffle(Arrays.asList(elements)); |
342 |
> |
shuffle(elements); |
343 |
|
Collection<Integer> full = populatedSet(elements); |
344 |
|
|
345 |
|
Arrays.fill(a, 42); |
353 |
|
assertSame(a, full.toArray(a)); |
354 |
|
assertTrue(Arrays.equals(elements, a)); |
355 |
|
|
356 |
< |
a = new Integer[2*SIZE]; |
356 |
> |
a = new Integer[2 * SIZE]; |
357 |
|
Arrays.fill(a, 42); |
358 |
|
assertSame(a, full.toArray(a)); |
359 |
|
assertTrue(Arrays.equals(elements, Arrays.copyOf(a, SIZE))); |
367 |
|
* not store the objects inside the set |
368 |
|
*/ |
369 |
|
public void testToArray_ArrayStoreException() { |
370 |
+ |
CopyOnWriteArraySet c = new CopyOnWriteArraySet(); |
371 |
+ |
c.add("zfasdfsdf"); |
372 |
+ |
c.add("asdadasd"); |
373 |
|
try { |
326 |
– |
CopyOnWriteArraySet c = new CopyOnWriteArraySet(); |
327 |
– |
c.add("zfasdfsdf"); |
328 |
– |
c.add("asdadasd"); |
374 |
|
c.toArray(new Long[5]); |
375 |
|
shouldThrow(); |
376 |
|
} catch (ArrayStoreException success) {} |