--- jsr166/src/test/tck/AtomicIntegerArrayTest.java 2011/03/15 19:47:06 1.20 +++ jsr166/src/test/tck/AtomicIntegerArrayTest.java 2011/06/10 19:45:01 1.23 @@ -7,9 +7,8 @@ */ import junit.framework.*; -import java.util.concurrent.atomic.*; -import java.io.*; -import java.util.*; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicIntegerArray; public class AtomicIntegerArrayTest extends JSR166TestCase { @@ -20,7 +19,6 @@ public class AtomicIntegerArrayTest exte return new TestSuite(AtomicIntegerArrayTest.class); } - /** * constructor creates array of given size with all elements zero */ @@ -45,7 +43,7 @@ public class AtomicIntegerArrayTest exte * constructor with array is of same size and has all elements */ public void testConstructor2() { - int[] a = { 17, 3, -42, 99, -7}; + int[] a = { 17, 3, -42, 99, -7 }; AtomicIntegerArray ai = new AtomicIntegerArray(a); assertEquals(a.length, ai.length()); for (int i = 0; i < a.length; ++i) @@ -307,34 +305,26 @@ public class AtomicIntegerArrayTest exte assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN); } - /** * a deserialized serialized array holds same values */ public void testSerialization() throws Exception { - AtomicIntegerArray l = new AtomicIntegerArray(SIZE); - for (int i = 0; i < SIZE; ++i) - l.set(i, -i); - - ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); - ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); - out.writeObject(l); - out.close(); - - ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); - ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); - AtomicIntegerArray r = (AtomicIntegerArray) in.readObject(); - for (int i = 0; i < SIZE; ++i) { - assertEquals(l.get(i), r.get(i)); + AtomicIntegerArray x = new AtomicIntegerArray(SIZE); + for (int i = 0; i < SIZE; i++) + x.set(i, -i); + AtomicIntegerArray y = serialClone(x); + assertTrue(x != y); + assertEquals(x.length(), y.length()); + for (int i = 0; i < SIZE; i++) { + assertEquals(x.get(i), y.get(i)); } } - /** * toString returns current value. */ public void testToString() { - int[] a = { 17, 3, -42, 99, -7}; + int[] a = { 17, 3, -42, 99, -7 }; AtomicIntegerArray ai = new AtomicIntegerArray(a); assertEquals(Arrays.toString(a), ai.toString()); }