--- jsr166/src/test/tck/AtomicLongFieldUpdaterTest.java 2011/06/10 20:17:11 1.23 +++ jsr166/src/test/tck/AtomicLongFieldUpdaterTest.java 2013/04/02 04:11:28 1.25 @@ -21,40 +21,41 @@ public class AtomicLongFieldUpdaterTest return new TestSuite(AtomicLongFieldUpdaterTest.class); } + AtomicLongFieldUpdater updaterFor(String fieldName) { + return AtomicLongFieldUpdater.newUpdater + (AtomicLongFieldUpdaterTest.class, fieldName); + } + /** * Construction with non-existent field throws RuntimeException */ public void testConstructor() { try { - AtomicLongFieldUpdater - a = AtomicLongFieldUpdater.newUpdater - (AtomicLongFieldUpdaterTest.class, "y"); + updaterFor("y"); shouldThrow(); - } catch (RuntimeException success) {} + } catch (RuntimeException success) { + assertTrue(success.getCause() != null); + } } /** - * construction with field not of given type throws RuntimeException + * construction with field not of given type throws IllegalArgumentException */ public void testConstructor2() { try { - AtomicLongFieldUpdater - a = AtomicLongFieldUpdater.newUpdater - (AtomicLongFieldUpdaterTest.class, "z"); + updaterFor("z"); shouldThrow(); - } catch (RuntimeException success) {} + } catch (IllegalArgumentException success) {} } /** - * construction with non-volatile field throws RuntimeException + * construction with non-volatile field throws IllegalArgumentException */ public void testConstructor3() { try { - AtomicLongFieldUpdater - a = AtomicLongFieldUpdater.newUpdater - (AtomicLongFieldUpdaterTest.class, "w"); + updaterFor("w"); shouldThrow(); - } catch (RuntimeException success) {} + } catch (IllegalArgumentException success) {} } /** @@ -62,11 +63,7 @@ public class AtomicLongFieldUpdaterTest */ public void testGetSet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(1, a.get(this)); a.set(this, 2); @@ -80,11 +77,7 @@ public class AtomicLongFieldUpdaterTest */ public void testGetLazySet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(1, a.get(this)); a.lazySet(this, 2); @@ -98,11 +91,7 @@ public class AtomicLongFieldUpdaterTest */ public void testCompareAndSet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertTrue(a.compareAndSet(this, 1, 2)); assertTrue(a.compareAndSet(this, 2, -4)); @@ -119,12 +108,8 @@ public class AtomicLongFieldUpdaterTest */ public void testCompareAndSetInMultipleThreads() throws Exception { x = 1; - final AtomicLongFieldUpdatera; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + final AtomicLongFieldUpdater a; + a = updaterFor("x"); Thread t = new Thread(new CheckedRunnable() { public void realRun() { @@ -145,11 +130,7 @@ public class AtomicLongFieldUpdaterTest */ public void testWeakCompareAndSet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; while (!a.weakCompareAndSet(this, 1, 2)); while (!a.weakCompareAndSet(this, 2, -4)); @@ -163,11 +144,7 @@ public class AtomicLongFieldUpdaterTest */ public void testGetAndSet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(1, a.getAndSet(this, 0)); assertEquals(0, a.getAndSet(this, -10)); @@ -179,11 +156,7 @@ public class AtomicLongFieldUpdaterTest */ public void testGetAndAdd() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(1, a.getAndAdd(this, 2)); assertEquals(3, a.get(this)); @@ -196,11 +169,7 @@ public class AtomicLongFieldUpdaterTest */ public void testGetAndDecrement() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(1, a.getAndDecrement(this)); assertEquals(0, a.getAndDecrement(this)); @@ -212,11 +181,7 @@ public class AtomicLongFieldUpdaterTest */ public void testGetAndIncrement() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(1, a.getAndIncrement(this)); assertEquals(2, a.get(this)); @@ -232,11 +197,7 @@ public class AtomicLongFieldUpdaterTest */ public void testAddAndGet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(3, a.addAndGet(this, 2)); assertEquals(3, a.get(this)); @@ -249,11 +210,7 @@ public class AtomicLongFieldUpdaterTest */ public void testDecrementAndGet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(0, a.decrementAndGet(this)); assertEquals(-1, a.decrementAndGet(this)); @@ -266,11 +223,7 @@ public class AtomicLongFieldUpdaterTest */ public void testIncrementAndGet() { AtomicLongFieldUpdater a; - try { - a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x"); - } catch (RuntimeException ok) { - return; - } + a = updaterFor("x"); x = 1; assertEquals(2, a.incrementAndGet(this)); assertEquals(2, a.get(this));