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.20 by jsr166, Fri May 27 19:39:07 2011 UTC vs.
Revision 1.23 by jsr166, Fri Jun 10 19:45:01 2011 UTC

# Line 7 | Line 7
7   */
8  
9   import junit.framework.*;
10 < import java.util.concurrent.atomic.*;
11 < import java.io.*;
12 < import java.util.*;
10 > import java.util.Arrays;
11 > import java.util.concurrent.atomic.AtomicReferenceArray;
12  
13   public class AtomicReferenceArrayTest extends JSR166TestCase {
14      public static void main(String[] args) {
# Line 44 | Line 43 | public class AtomicReferenceArrayTest ex
43       * constructor with array is of same size and has all elements
44       */
45      public void testConstructor2() {
46 <        Integer[] a = { two, one, three, four, seven};
46 >        Integer[] a = { two, one, three, four, seven };
47          AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
48          assertEquals(a.length, ai.length());
49          for (int i = 0; i < a.length; ++i)
# Line 52 | Line 51 | public class AtomicReferenceArrayTest ex
51      }
52  
53      /**
54 +     * Initialize AtomicReference<Class> with SubClass[]
55 +     */
56 +    public void testConstructorSubClassArray() {
57 +        Integer[] a = { two, one, three, four, seven };
58 +        AtomicReferenceArray<Number> aa = new AtomicReferenceArray<Number>(a);
59 +        assertEquals(a.length, aa.length());
60 +        for (int i = 0; i < a.length; ++i) {
61 +            assertSame(a[i], aa.get(i));
62 +            Long x = Long.valueOf(i);
63 +            aa.set(i, x);
64 +            assertSame(x, aa.get(i));
65 +        }
66 +    }
67 +
68 +    /**
69       * get and set for out of bound indices throw IndexOutOfBoundsException
70       */
71      public void testIndexing() {
# Line 178 | Line 192 | public class AtomicReferenceArrayTest ex
192       * a deserialized serialized array holds same values
193       */
194      public void testSerialization() throws Exception {
195 <        AtomicReferenceArray l = new AtomicReferenceArray(SIZE);
196 <        for (int i = 0; i < SIZE; ++i) {
197 <            l.set(i, new Integer(-i));
198 <        }
199 <
200 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
201 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
202 <        out.writeObject(l);
203 <        out.close();
190 <
191 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
192 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
193 <        AtomicReferenceArray r = (AtomicReferenceArray) in.readObject();
194 <        assertEquals(l.length(), r.length());
195 <        for (int i = 0; i < SIZE; ++i) {
196 <            assertEquals(r.get(i), l.get(i));
195 >        AtomicReferenceArray x = new AtomicReferenceArray(SIZE);
196 >        for (int i = 0; i < SIZE; i++) {
197 >            x.set(i, new Integer(-i));
198 >        }
199 >        AtomicReferenceArray y = serialClone(x);
200 >        assertTrue(x != y);
201 >        assertEquals(x.length(), y.length());
202 >        for (int i = 0; i < SIZE; i++) {
203 >            assertEquals(x.get(i), y.get(i));
204          }
205      }
206  
# Line 201 | Line 208 | public class AtomicReferenceArrayTest ex
208       * toString returns current value.
209       */
210      public void testToString() {
211 <        Integer[] a = { two, one, three, four, seven};
211 >        Integer[] a = { two, one, three, four, seven };
212          AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
213          assertEquals(Arrays.toString(a), ai.toString());
214      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines