--- jsr166/src/test/tck/AtomicReferenceArrayTest.java 2011/08/10 07:14:48 1.26 +++ jsr166/src/test/tck/AtomicReferenceArrayTest.java 2018/01/07 22:59:17 1.38 @@ -6,13 +6,15 @@ * Pat Fisher, Mike Judd. */ -import junit.framework.*; import java.util.Arrays; import java.util.concurrent.atomic.AtomicReferenceArray; +import junit.framework.Test; +import junit.framework.TestSuite; + public class AtomicReferenceArrayTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(AtomicReferenceArrayTest.class); @@ -22,7 +24,7 @@ public class AtomicReferenceArrayTest ex * constructor creates array of given size with all elements null */ public void testConstructor() { - AtomicReferenceArray aa = new AtomicReferenceArray(SIZE); + AtomicReferenceArray aa = new AtomicReferenceArray<>(SIZE); for (int i = 0; i < SIZE; i++) { assertNull(aa.get(i)); } @@ -34,7 +36,7 @@ public class AtomicReferenceArrayTest ex public void testConstructor2NPE() { try { Integer[] a = null; - AtomicReferenceArray aa = new AtomicReferenceArray(a); + new AtomicReferenceArray(a); shouldThrow(); } catch (NullPointerException success) {} } @@ -44,18 +46,18 @@ public class AtomicReferenceArrayTest ex */ public void testConstructor2() { Integer[] a = { two, one, three, four, seven }; - AtomicReferenceArray aa = new AtomicReferenceArray(a); + AtomicReferenceArray aa = new AtomicReferenceArray<>(a); assertEquals(a.length, aa.length()); for (int i = 0; i < a.length; i++) assertEquals(a[i], aa.get(i)); } /** - * Initialize AtomicReference with SubClass[] + * Initialize AtomicReferenceArray with SubClass[] */ public void testConstructorSubClassArray() { Integer[] a = { two, one, three, four, seven }; - AtomicReferenceArray aa = new AtomicReferenceArray(a); + AtomicReferenceArray aa = new AtomicReferenceArray<>(a); assertEquals(a.length, aa.length()); for (int i = 0; i < a.length; i++) { assertSame(a[i], aa.get(i)); @@ -69,7 +71,7 @@ public class AtomicReferenceArrayTest ex * get and set for out of bound indices throw IndexOutOfBoundsException */ public void testIndexing() { - AtomicReferenceArray aa = new AtomicReferenceArray(SIZE); + AtomicReferenceArray aa = new AtomicReferenceArray<>(SIZE); for (int index : new int[] { -1, SIZE }) { try { aa.get(index); @@ -169,10 +171,10 @@ public class AtomicReferenceArrayTest ex AtomicReferenceArray aa = new AtomicReferenceArray(SIZE); for (int i = 0; i < SIZE; i++) { aa.set(i, one); - while (!aa.weakCompareAndSet(i, one, two)); - while (!aa.weakCompareAndSet(i, two, m4)); + do {} while (!aa.weakCompareAndSet(i, one, two)); + do {} while (!aa.weakCompareAndSet(i, two, m4)); assertSame(m4, aa.get(i)); - while (!aa.weakCompareAndSet(i, m4, seven)); + do {} while (!aa.weakCompareAndSet(i, m4, seven)); assertSame(seven, aa.get(i)); } } @@ -191,7 +193,7 @@ public class AtomicReferenceArrayTest ex } /** - * a deserialized serialized array holds same values + * a deserialized/reserialized array holds same values in same order */ public void testSerialization() throws Exception { AtomicReferenceArray x = new AtomicReferenceArray(SIZE); @@ -199,7 +201,7 @@ public class AtomicReferenceArrayTest ex x.set(i, new Integer(-i)); } AtomicReferenceArray y = serialClone(x); - assertTrue(x != y); + assertNotSame(x, y); assertEquals(x.length(), y.length()); for (int i = 0; i < SIZE; i++) { assertEquals(x.get(i), y.get(i)); @@ -211,7 +213,8 @@ public class AtomicReferenceArrayTest ex */ public void testToString() { Integer[] a = { two, one, three, four, seven }; - AtomicReferenceArray aa = new AtomicReferenceArray(a); + AtomicReferenceArray aa = new AtomicReferenceArray<>(a); assertEquals(Arrays.toString(a), aa.toString()); } + }