--- jsr166/src/test/tck/AtomicReferenceTest.java 2003/08/31 19:24:53 1.1 +++ jsr166/src/test/tck/AtomicReferenceTest.java 2003/09/20 18:20:07 1.4 @@ -7,8 +7,9 @@ import junit.framework.*; import java.util.concurrent.atomic.*; +import java.io.*; -public class AtomicReferenceTest extends TestCase { +public class AtomicReferenceTest extends JSR166TestCase { public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } @@ -16,25 +17,25 @@ public class AtomicReferenceTest extends return new TestSuite(AtomicReferenceTest.class); } - static final Integer zero = new Integer(0); - static final Integer one = new Integer(1); - static final Integer two = new Integer(2); - static final Integer m3 = new Integer(-3); - static final Integer m4 = new Integer(-4); - static final Integer m5 = new Integer(-5); - static final Integer seven = new Integer(7); - static final Integer m10 = new Integer(-10); - + /** + * + */ public void testConstructor(){ AtomicReference ai = new AtomicReference(one); assertEquals(one,ai.get()); } + /** + * + */ public void testConstructor2(){ AtomicReference ai = new AtomicReference(); assertNull(ai.get()); } + /** + * + */ public void testGetSet(){ AtomicReference ai = new AtomicReference(one); assertEquals(one,ai.get()); @@ -44,6 +45,9 @@ public class AtomicReferenceTest extends assertEquals(m3,ai.get()); } + /** + * + */ public void testCompareAndSet(){ AtomicReference ai = new AtomicReference(one); assertTrue(ai.compareAndSet(one,two)); @@ -55,6 +59,9 @@ public class AtomicReferenceTest extends assertEquals(seven,ai.get()); } + /** + * + */ public void testWeakCompareAndSet(){ AtomicReference ai = new AtomicReference(one); while(!ai.weakCompareAndSet(one,two)); @@ -64,6 +71,9 @@ public class AtomicReferenceTest extends assertEquals(seven,ai.get()); } + /** + * + */ public void testGetAndSet(){ AtomicReference ai = new AtomicReference(one); assertEquals(one,ai.getAndSet(zero)); @@ -71,5 +81,27 @@ public class AtomicReferenceTest extends assertEquals(m10,ai.getAndSet(one)); } + /** + * + */ + public void testSerialization() { + AtomicReference l = new AtomicReference(); + + try { + l.set(one); + 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)); + AtomicReference r = (AtomicReference) in.readObject(); + assertEquals(l.get(), r.get()); + } catch(Exception e){ + unexpectedException(); + } + } + }