ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArraySetTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CopyOnWriteArraySetTest.java (file contents):
Revision 1.3 by dl, Sun Sep 14 20:42:40 2003 UTC vs.
Revision 1.4 by dl, Sat Sep 20 18:20:07 2003 UTC

# Line 30 | Line 30 | public class CopyOnWriteArraySetTest ext
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)
# Line 48 | Line 54 | public class CopyOnWriteArraySetTest ext
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);
# Line 62 | Line 68 | public class CopyOnWriteArraySetTest ext
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);
# Line 75 | Line 81 | public class CopyOnWriteArraySetTest ext
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));
# Line 93 | Line 100 | public class CopyOnWriteArraySetTest ext
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());
# Line 102 | Line 109 | public class CopyOnWriteArraySetTest ext
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);
# Line 127 | Line 137 | public class CopyOnWriteArraySetTest ext
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);
# Line 140 | Line 150 | public class CopyOnWriteArraySetTest ext
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());
# Line 150 | Line 160 | public class CopyOnWriteArraySetTest ext
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;
# Line 159 | Line 169 | public class CopyOnWriteArraySetTest ext
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) {
# Line 182 | Line 198 | public class CopyOnWriteArraySetTest ext
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);
# Line 192 | Line 208 | public class CopyOnWriteArraySetTest ext
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));
# Line 202 | Line 221 | public class CopyOnWriteArraySetTest ext
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());
# Line 212 | Line 231 | public class CopyOnWriteArraySetTest ext
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);
# Line 222 | Line 241 | public class CopyOnWriteArraySetTest ext
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);
# Line 235 | Line 255 | public class CopyOnWriteArraySetTest ext
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  
# Line 268 | Line 288 | public class CopyOnWriteArraySetTest ext
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines