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

Comparing jsr166/src/test/tck/AtomicReferenceArrayTest.java (file contents):
Revision 1.6 by dl, Sat Dec 27 19:26:43 2003 UTC vs.
Revision 1.10 by dl, Wed May 25 14:27:37 2005 UTC

# Line 9 | Line 9
9   import junit.framework.*;
10   import java.util.concurrent.atomic.*;
11   import java.io.*;
12 + import java.util.*;
13  
14   public class AtomicReferenceArrayTest extends JSR166TestCase
15   {
# Line 30 | Line 31 | public class AtomicReferenceArrayTest ex
31      }
32  
33      /**
34 +     * constructor with null array throws NPE
35 +     */
36 +    public void testConstructor2NPE() {
37 +        try {
38 +            Integer[] a = null;
39 +            AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
40 +        } catch (NullPointerException success) {
41 +        } catch (Exception ex) {
42 +            unexpectedException();
43 +        }
44 +    }
45 +
46 +    /**
47 +     * constructor with array is of same size and has all elements
48 +     */
49 +    public void testConstructor2() {
50 +        Integer[] a = { two, one, three, four, seven};
51 +        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
52 +        assertEquals(a.length, ai.length());
53 +        for (int i = 0; i < a.length; ++i)
54 +            assertEquals(a[i], ai.get(i));
55 +    }
56 +
57 +
58 +    /**
59       * get and set for out of bound indices throw IndexOutOfBoundsException
60       */
61      public void testIndexing(){
# Line 68 | Line 94 | public class AtomicReferenceArrayTest ex
94      }
95  
96      /**
97 +     * get returns the last value lazySet at index by same thread
98 +     */
99 +    public void testGetLazySet(){
100 +        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
101 +        for (int i = 0; i < SIZE; ++i) {
102 +            ai.lazySet(i, one);
103 +            assertEquals(one,ai.get(i));
104 +            ai.lazySet(i, two);
105 +            assertEquals(two,ai.get(i));
106 +            ai.lazySet(i, m3);
107 +            assertEquals(m3,ai.get(i));
108 +        }
109 +    }
110 +
111 +    /**
112       * compareAndSet succeeds in changing value if equal to expected else fails
113       */
114      public void testCompareAndSet(){
# Line 163 | Line 204 | public class AtomicReferenceArrayTest ex
204          }
205      }
206  
207 +
208 +    /**
209 +     * toString returns current value.
210 +     */
211 +    public void testToString() {
212 +        Integer[] a = { two, one, three, four, seven};
213 +        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
214 +        assertEquals(Arrays.toString(a), ai.toString());
215 +    }
216   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines