--- jsr166/src/test/tck/AtomicReferenceFieldUpdaterTest.java 2013/04/01 20:58:58 1.26 +++ jsr166/src/test/tck/AtomicReferenceFieldUpdaterTest.java 2014/12/31 21:50:25 1.32 @@ -6,13 +6,16 @@ * Pat Fisher, Mike Judd. */ -import junit.framework.*; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; +import junit.framework.Test; +import junit.framework.TestSuite; + public class AtomicReferenceFieldUpdaterTest extends JSR166TestCase { volatile Integer x = null; Object z; Integer w; + volatile int i; public static void main(String[] args) { junit.textui.TestRunner.run(suite()); @@ -33,34 +36,46 @@ public class AtomicReferenceFieldUpdater try { updaterFor("y"); shouldThrow(); - } catch (RuntimeException success) {} + } catch (RuntimeException success) { + assertNotNull(success.getCause()); + } } /** - * construction with field not of given type throws RuntimeException + * construction with field not of given type throws ClassCastException */ public void testConstructor2() { try { updaterFor("z"); shouldThrow(); - } catch (RuntimeException success) {} + } catch (ClassCastException success) {} } /** - * Constructor with non-volatile field throws exception + * Constructor with non-volatile field throws IllegalArgumentException */ public void testConstructor3() { try { updaterFor("w"); shouldThrow(); - } catch (RuntimeException success) {} + } catch (IllegalArgumentException success) {} + } + + /** + * Constructor with non-reference field throws ClassCastException + */ + public void testConstructor4() { + try { + updaterFor("i"); + shouldThrow(); + } catch (ClassCastException success) {} } /** * get returns the last value set or assigned */ public void testGetSet() { - AtomicReferenceFieldUpdatera; + AtomicReferenceFieldUpdater a; a = updaterFor("x"); x = one; assertSame(one, a.get(this)); @@ -74,7 +89,7 @@ public class AtomicReferenceFieldUpdater * get returns the last value lazySet by same thread */ public void testGetLazySet() { - AtomicReferenceFieldUpdatera; + AtomicReferenceFieldUpdater a; a = updaterFor("x"); x = one; assertSame(one, a.get(this)); @@ -88,7 +103,7 @@ public class AtomicReferenceFieldUpdater * compareAndSet succeeds in changing value if equal to expected else fails */ public void testCompareAndSet() { - AtomicReferenceFieldUpdatera; + AtomicReferenceFieldUpdater a; a = updaterFor("x"); x = one; assertTrue(a.compareAndSet(this, one, two)); @@ -106,7 +121,7 @@ public class AtomicReferenceFieldUpdater */ public void testCompareAndSetInMultipleThreads() throws Exception { x = one; - final AtomicReferenceFieldUpdatera; + final AtomicReferenceFieldUpdater a; a = updaterFor("x"); Thread t = new Thread(new CheckedRunnable() { @@ -127,13 +142,13 @@ public class AtomicReferenceFieldUpdater * to expected */ public void testWeakCompareAndSet() { - AtomicReferenceFieldUpdatera; + AtomicReferenceFieldUpdater a; a = updaterFor("x"); x = one; - while (!a.weakCompareAndSet(this, one, two)); - while (!a.weakCompareAndSet(this, two, m4)); + do {} while (!a.weakCompareAndSet(this, one, two)); + do {} while (!a.weakCompareAndSet(this, two, m4)); assertSame(m4, a.get(this)); - while (!a.weakCompareAndSet(this, m4, seven)); + do {} while (!a.weakCompareAndSet(this, m4, seven)); assertSame(seven, a.get(this)); } @@ -141,7 +156,7 @@ public class AtomicReferenceFieldUpdater * getAndSet returns previous value and sets to given value */ public void testGetAndSet() { - AtomicReferenceFieldUpdatera; + AtomicReferenceFieldUpdater a; a = updaterFor("x"); x = one; assertSame(one, a.getAndSet(this, zero));