2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
< |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
< |
* Pat Fisher, Mike Judd. |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
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); |
22 |
|
static CopyOnWriteArraySet populatedSet(int n){ |
23 |
|
CopyOnWriteArraySet a = new CopyOnWriteArraySet(); |
24 |
|
assertTrue(a.isEmpty()); |
25 |
< |
for (int i = 0; i < n; ++i) |
25 |
> |
for (int i = 0; i < n; ++i) |
26 |
|
a.add(new Integer(i)); |
27 |
|
assertFalse(a.isEmpty()); |
28 |
|
assertEquals(n, a.size()); |
45 |
|
for (int i = 0; i < SIZE-1; ++i) |
46 |
|
ints[i] = new Integer(i); |
47 |
|
CopyOnWriteArraySet a = new CopyOnWriteArraySet(Arrays.asList(ints)); |
48 |
< |
for (int i = 0; i < SIZE; ++i) |
48 |
> |
for (int i = 0; i < SIZE; ++i) |
49 |
|
assertTrue(a.contains(ints[i])); |
50 |
|
} |
51 |
< |
|
51 |
> |
|
52 |
|
|
53 |
|
/** |
54 |
|
* addAll adds each element from the given collection |
132 |
|
assertEquals(a.hashCode(), b.hashCode()); |
133 |
|
} |
134 |
|
|
135 |
< |
|
135 |
> |
|
136 |
|
/** |
137 |
|
* containsAll returns true for collections with subset of elements |
138 |
|
*/ |
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++) |
166 |
> |
for (j = 0; i.hasNext(); j++) |
167 |
|
assertEquals(j, ((Integer)i.next()).intValue()); |
168 |
|
assertEquals(3, j); |
169 |
|
} |
191 |
|
for (int i = 0; i < 3; ++i) { |
192 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
193 |
|
} |
194 |
< |
} |
194 |
> |
} |
195 |
|
|
196 |
|
|
197 |
|
/** |
265 |
|
c.add("asdadasd"); |
266 |
|
c.toArray(new Long[5]); |
267 |
|
shouldThrow(); |
268 |
< |
} catch(ArrayStoreException e){} |
268 |
> |
} catch (ArrayStoreException e){} |
269 |
|
} |
270 |
|
|
271 |
|
/** |
286 |
|
assertEquals(q.size(), r.size()); |
287 |
|
assertTrue(q.equals(r)); |
288 |
|
assertTrue(r.equals(q)); |
289 |
< |
} catch(Exception e){ |
289 |
> |
} catch (Exception e){ |
290 |
|
unexpectedException(); |
291 |
|
} |
292 |
|
} |