--- jsr166/src/test/tck/Atomic8Test.java 2019/02/22 19:27:47 1.10 +++ jsr166/src/test/tck/Atomic8Test.java 2021/01/26 13:33:05 1.11 @@ -32,16 +32,16 @@ public class Atomic8Test extends JSR166T static long addLong17(long x) { return x + 17; } static int addInt17(int x) { return x + 17; } - static Integer addInteger17(Integer x) { - return x.intValue() + 17; + static Item addItem17(Item x) { + return new Item(x.intValue() + 17); } - static Integer sumInteger(Integer x, Integer y) { - return x.intValue() + y.intValue(); + static Item sumItem(Item x, Item y) { + return new Item(x.intValue() + y.intValue()); } volatile long aLongField; volatile int anIntField; - volatile Integer anIntegerField; + volatile Item anItemField; AtomicLongFieldUpdater aLongFieldUpdater() { return AtomicLongFieldUpdater.newUpdater @@ -53,9 +53,9 @@ public class Atomic8Test extends JSR166T (Atomic8Test.class, "anIntField"); } - AtomicReferenceFieldUpdater anIntegerFieldUpdater() { + AtomicReferenceFieldUpdater anItemFieldUpdater() { return AtomicReferenceFieldUpdater.newUpdater - (Atomic8Test.class, Integer.class, "anIntegerField"); + (Atomic8Test.class, Item.class, "anItemField"); } /** @@ -64,9 +64,9 @@ public class Atomic8Test extends JSR166T */ public void testLongGetAndUpdate() { AtomicLong a = new AtomicLong(1L); - assertEquals(1L, a.getAndUpdate(Atomic8Test::addLong17)); - assertEquals(18L, a.getAndUpdate(Atomic8Test::addLong17)); - assertEquals(35L, a.get()); + mustEqual(1L, a.getAndUpdate(Atomic8Test::addLong17)); + mustEqual(18L, a.getAndUpdate(Atomic8Test::addLong17)); + mustEqual(35L, a.get()); } /** @@ -75,8 +75,8 @@ public class Atomic8Test extends JSR166T */ public void testLongUpdateAndGet() { AtomicLong a = new AtomicLong(1L); - assertEquals(18L, a.updateAndGet(Atomic8Test::addLong17)); - assertEquals(35L, a.updateAndGet(Atomic8Test::addLong17)); + mustEqual(18L, a.updateAndGet(Atomic8Test::addLong17)); + mustEqual(35L, a.updateAndGet(Atomic8Test::addLong17)); } /** @@ -85,9 +85,9 @@ public class Atomic8Test extends JSR166T */ public void testLongGetAndAccumulate() { AtomicLong a = new AtomicLong(1L); - assertEquals(1L, a.getAndAccumulate(2L, Long::sum)); - assertEquals(3L, a.getAndAccumulate(3L, Long::sum)); - assertEquals(6L, a.get()); + mustEqual(1L, a.getAndAccumulate(2L, Long::sum)); + mustEqual(3L, a.getAndAccumulate(3L, Long::sum)); + mustEqual(6L, a.get()); } /** @@ -96,9 +96,9 @@ public class Atomic8Test extends JSR166T */ public void testLongAccumulateAndGet() { AtomicLong a = new AtomicLong(1L); - assertEquals(7L, a.accumulateAndGet(6L, Long::sum)); - assertEquals(10L, a.accumulateAndGet(3L, Long::sum)); - assertEquals(10L, a.get()); + mustEqual(7L, a.accumulateAndGet(6L, Long::sum)); + mustEqual(10L, a.accumulateAndGet(3L, Long::sum)); + mustEqual(10L, a.get()); } /** @@ -107,9 +107,9 @@ public class Atomic8Test extends JSR166T */ public void testIntGetAndUpdate() { AtomicInteger a = new AtomicInteger(1); - assertEquals(1, a.getAndUpdate(Atomic8Test::addInt17)); - assertEquals(18, a.getAndUpdate(Atomic8Test::addInt17)); - assertEquals(35, a.get()); + mustEqual(1, a.getAndUpdate(Atomic8Test::addInt17)); + mustEqual(18, a.getAndUpdate(Atomic8Test::addInt17)); + mustEqual(35, a.get()); } /** @@ -118,9 +118,9 @@ public class Atomic8Test extends JSR166T */ public void testIntUpdateAndGet() { AtomicInteger a = new AtomicInteger(1); - assertEquals(18, a.updateAndGet(Atomic8Test::addInt17)); - assertEquals(35, a.updateAndGet(Atomic8Test::addInt17)); - assertEquals(35, a.get()); + mustEqual(18, a.updateAndGet(Atomic8Test::addInt17)); + mustEqual(35, a.updateAndGet(Atomic8Test::addInt17)); + mustEqual(35, a.get()); } /** @@ -129,9 +129,9 @@ public class Atomic8Test extends JSR166T */ public void testIntGetAndAccumulate() { AtomicInteger a = new AtomicInteger(1); - assertEquals(1, a.getAndAccumulate(2, Integer::sum)); - assertEquals(3, a.getAndAccumulate(3, Integer::sum)); - assertEquals(6, a.get()); + mustEqual(1, a.getAndAccumulate(2, Integer::sum)); + mustEqual(3, a.getAndAccumulate(3, Integer::sum)); + mustEqual(6, a.get()); } /** @@ -140,9 +140,9 @@ public class Atomic8Test extends JSR166T */ public void testIntAccumulateAndGet() { AtomicInteger a = new AtomicInteger(1); - assertEquals(7, a.accumulateAndGet(6, Integer::sum)); - assertEquals(10, a.accumulateAndGet(3, Integer::sum)); - assertEquals(10, a.get()); + mustEqual(7, a.accumulateAndGet(6, Integer::sum)); + mustEqual(10, a.accumulateAndGet(3, Integer::sum)); + mustEqual(10, a.get()); } /** @@ -150,10 +150,10 @@ public class Atomic8Test extends JSR166T * result of supplied function */ public void testReferenceGetAndUpdate() { - AtomicReference a = new AtomicReference<>(one); - assertEquals((Integer) 1, a.getAndUpdate(Atomic8Test::addInteger17)); - assertEquals((Integer) 18, a.getAndUpdate(Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.get()); + AtomicReference a = new AtomicReference<>(one); + mustEqual(1, a.getAndUpdate(Atomic8Test::addItem17)); + mustEqual(18, a.getAndUpdate(Atomic8Test::addItem17)); + mustEqual(35, a.get()); } /** @@ -161,10 +161,10 @@ public class Atomic8Test extends JSR166T * returns result. */ public void testReferenceUpdateAndGet() { - AtomicReference a = new AtomicReference<>(one); - assertEquals((Integer) 18, a.updateAndGet(Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.updateAndGet(Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.get()); + AtomicReference a = new AtomicReference<>(one); + mustEqual(18, a.updateAndGet(Atomic8Test::addItem17)); + mustEqual(35, a.updateAndGet(Atomic8Test::addItem17)); + mustEqual(35, a.get()); } /** @@ -172,10 +172,10 @@ public class Atomic8Test extends JSR166T * with supplied function. */ public void testReferenceGetAndAccumulate() { - AtomicReference a = new AtomicReference<>(one); - assertEquals((Integer) 1, a.getAndAccumulate(2, Atomic8Test::sumInteger)); - assertEquals((Integer) 3, a.getAndAccumulate(3, Atomic8Test::sumInteger)); - assertEquals((Integer) 6, a.get()); + AtomicReference a = new AtomicReference<>(one); + mustEqual( 1, a.getAndAccumulate(two, Atomic8Test::sumItem)); + mustEqual( 3, a.getAndAccumulate(three, Atomic8Test::sumItem)); + mustEqual( 6, a.get()); } /** @@ -183,10 +183,10 @@ public class Atomic8Test extends JSR166T * returns result. */ public void testReferenceAccumulateAndGet() { - AtomicReference a = new AtomicReference<>(one); - assertEquals((Integer) 7, a.accumulateAndGet(6, Atomic8Test::sumInteger)); - assertEquals((Integer) 10, a.accumulateAndGet(3, Atomic8Test::sumInteger)); - assertEquals((Integer) 10, a.get()); + AtomicReference a = new AtomicReference<>(one); + mustEqual( 7, a.accumulateAndGet(six, Atomic8Test::sumItem)); + mustEqual( 10, a.accumulateAndGet(three, Atomic8Test::sumItem)); + mustEqual( 10, a.get()); } /** @@ -196,9 +196,9 @@ public class Atomic8Test extends JSR166T public void testLongArrayGetAndUpdate() { AtomicLongArray a = new AtomicLongArray(1); a.set(0, 1); - assertEquals(1L, a.getAndUpdate(0, Atomic8Test::addLong17)); - assertEquals(18L, a.getAndUpdate(0, Atomic8Test::addLong17)); - assertEquals(35L, a.get(0)); + mustEqual(1L, a.getAndUpdate(0, Atomic8Test::addLong17)); + mustEqual(18L, a.getAndUpdate(0, Atomic8Test::addLong17)); + mustEqual(35L, a.get(0)); } /** @@ -208,9 +208,9 @@ public class Atomic8Test extends JSR166T public void testLongArrayUpdateAndGet() { AtomicLongArray a = new AtomicLongArray(1); a.set(0, 1); - assertEquals(18L, a.updateAndGet(0, Atomic8Test::addLong17)); - assertEquals(35L, a.updateAndGet(0, Atomic8Test::addLong17)); - assertEquals(35L, a.get(0)); + mustEqual(18L, a.updateAndGet(0, Atomic8Test::addLong17)); + mustEqual(35L, a.updateAndGet(0, Atomic8Test::addLong17)); + mustEqual(35L, a.get(0)); } /** @@ -220,9 +220,9 @@ public class Atomic8Test extends JSR166T public void testLongArrayGetAndAccumulate() { AtomicLongArray a = new AtomicLongArray(1); a.set(0, 1); - assertEquals(1L, a.getAndAccumulate(0, 2L, Long::sum)); - assertEquals(3L, a.getAndAccumulate(0, 3L, Long::sum)); - assertEquals(6L, a.get(0)); + mustEqual(1L, a.getAndAccumulate(0, 2L, Long::sum)); + mustEqual(3L, a.getAndAccumulate(0, 3L, Long::sum)); + mustEqual(6L, a.get(0)); } /** @@ -232,9 +232,9 @@ public class Atomic8Test extends JSR166T public void testLongArrayAccumulateAndGet() { AtomicLongArray a = new AtomicLongArray(1); a.set(0, 1); - assertEquals(7L, a.accumulateAndGet(0, 6L, Long::sum)); - assertEquals(10L, a.accumulateAndGet(0, 3L, Long::sum)); - assertEquals(10L, a.get(0)); + mustEqual(7L, a.accumulateAndGet(0, 6L, Long::sum)); + mustEqual(10L, a.accumulateAndGet(0, 3L, Long::sum)); + mustEqual(10L, a.get(0)); } /** @@ -244,9 +244,9 @@ public class Atomic8Test extends JSR166T public void testIntArrayGetAndUpdate() { AtomicIntegerArray a = new AtomicIntegerArray(1); a.set(0, 1); - assertEquals(1, a.getAndUpdate(0, Atomic8Test::addInt17)); - assertEquals(18, a.getAndUpdate(0, Atomic8Test::addInt17)); - assertEquals(35, a.get(0)); + mustEqual(1, a.getAndUpdate(0, Atomic8Test::addInt17)); + mustEqual(18, a.getAndUpdate(0, Atomic8Test::addInt17)); + mustEqual(35, a.get(0)); } /** @@ -256,9 +256,9 @@ public class Atomic8Test extends JSR166T public void testIntArrayUpdateAndGet() { AtomicIntegerArray a = new AtomicIntegerArray(1); a.set(0, 1); - assertEquals(18, a.updateAndGet(0, Atomic8Test::addInt17)); - assertEquals(35, a.updateAndGet(0, Atomic8Test::addInt17)); - assertEquals(35, a.get(0)); + mustEqual(18, a.updateAndGet(0, Atomic8Test::addInt17)); + mustEqual(35, a.updateAndGet(0, Atomic8Test::addInt17)); + mustEqual(35, a.get(0)); } /** @@ -268,9 +268,9 @@ public class Atomic8Test extends JSR166T public void testIntArrayGetAndAccumulate() { AtomicIntegerArray a = new AtomicIntegerArray(1); a.set(0, 1); - assertEquals(1, a.getAndAccumulate(0, 2, Integer::sum)); - assertEquals(3, a.getAndAccumulate(0, 3, Integer::sum)); - assertEquals(6, a.get(0)); + mustEqual(1, a.getAndAccumulate(0, 2, Integer::sum)); + mustEqual(3, a.getAndAccumulate(0, 3, Integer::sum)); + mustEqual(6, a.get(0)); } /** @@ -280,8 +280,8 @@ public class Atomic8Test extends JSR166T public void testIntArrayAccumulateAndGet() { AtomicIntegerArray a = new AtomicIntegerArray(1); a.set(0, 1); - assertEquals(7, a.accumulateAndGet(0, 6, Integer::sum)); - assertEquals(10, a.accumulateAndGet(0, 3, Integer::sum)); + mustEqual(7, a.accumulateAndGet(0, 6, Integer::sum)); + mustEqual(10, a.accumulateAndGet(0, 3, Integer::sum)); } /** @@ -289,11 +289,11 @@ public class Atomic8Test extends JSR166T * result of supplied function */ public void testReferenceArrayGetAndUpdate() { - AtomicReferenceArray a = new AtomicReferenceArray<>(1); + AtomicReferenceArray a = new AtomicReferenceArray<>(1); a.set(0, one); - assertEquals((Integer) 1, a.getAndUpdate(0, Atomic8Test::addInteger17)); - assertEquals((Integer) 18, a.getAndUpdate(0, Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.get(0)); + mustEqual( 1, a.getAndUpdate(0, Atomic8Test::addItem17)); + mustEqual( 18, a.getAndUpdate(0, Atomic8Test::addItem17)); + mustEqual( 35, a.get(0)); } /** @@ -301,10 +301,10 @@ public class Atomic8Test extends JSR166T * returns result. */ public void testReferenceArrayUpdateAndGet() { - AtomicReferenceArray a = new AtomicReferenceArray<>(1); + AtomicReferenceArray a = new AtomicReferenceArray<>(1); a.set(0, one); - assertEquals((Integer) 18, a.updateAndGet(0, Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.updateAndGet(0, Atomic8Test::addInteger17)); + mustEqual( 18, a.updateAndGet(0, Atomic8Test::addItem17)); + mustEqual( 35, a.updateAndGet(0, Atomic8Test::addItem17)); } /** @@ -312,11 +312,11 @@ public class Atomic8Test extends JSR166T * with supplied function. */ public void testReferenceArrayGetAndAccumulate() { - AtomicReferenceArray a = new AtomicReferenceArray<>(1); + AtomicReferenceArray a = new AtomicReferenceArray<>(1); a.set(0, one); - assertEquals((Integer) 1, a.getAndAccumulate(0, 2, Atomic8Test::sumInteger)); - assertEquals((Integer) 3, a.getAndAccumulate(0, 3, Atomic8Test::sumInteger)); - assertEquals((Integer) 6, a.get(0)); + mustEqual( 1, a.getAndAccumulate(0, two, Atomic8Test::sumItem)); + mustEqual( 3, a.getAndAccumulate(0, three, Atomic8Test::sumItem)); + mustEqual( 6, a.get(0)); } /** @@ -324,10 +324,10 @@ public class Atomic8Test extends JSR166T * returns result. */ public void testReferenceArrayAccumulateAndGet() { - AtomicReferenceArray a = new AtomicReferenceArray<>(1); + AtomicReferenceArray a = new AtomicReferenceArray<>(1); a.set(0, one); - assertEquals((Integer) 7, a.accumulateAndGet(0, 6, Atomic8Test::sumInteger)); - assertEquals((Integer) 10, a.accumulateAndGet(0, 3, Atomic8Test::sumInteger)); + mustEqual( 7, a.accumulateAndGet(0, six, Atomic8Test::sumItem)); + mustEqual( 10, a.accumulateAndGet(0, three, Atomic8Test::sumItem)); } /** @@ -335,12 +335,12 @@ public class Atomic8Test extends JSR166T * result of supplied function */ public void testLongFieldUpdaterGetAndUpdate() { - AtomicLongFieldUpdater a = aLongFieldUpdater(); - a.set(this, 1); - assertEquals(1L, a.getAndUpdate(this, Atomic8Test::addLong17)); - assertEquals(18L, a.getAndUpdate(this, Atomic8Test::addLong17)); - assertEquals(35L, a.get(this)); - assertEquals(35L, aLongField); + AtomicLongFieldUpdater a = aLongFieldUpdater(); + a.set(this, 1L); + mustEqual(1L, a.getAndUpdate(this, Atomic8Test::addLong17)); + mustEqual(18L, a.getAndUpdate(this, Atomic8Test::addLong17)); + mustEqual(35L, a.get(this)); + mustEqual(35L, aLongField); } /** @@ -348,12 +348,12 @@ public class Atomic8Test extends JSR166T * returns result. */ public void testLongFieldUpdaterUpdateAndGet() { - AtomicLongFieldUpdater a = aLongFieldUpdater(); - a.set(this, 1); - assertEquals(18L, a.updateAndGet(this, Atomic8Test::addLong17)); - assertEquals(35L, a.updateAndGet(this, Atomic8Test::addLong17)); - assertEquals(35L, a.get(this)); - assertEquals(35L, aLongField); + AtomicLongFieldUpdater a = aLongFieldUpdater(); + a.set(this, 1L); + mustEqual(18L, a.updateAndGet(this, Atomic8Test::addLong17)); + mustEqual(35L, a.updateAndGet(this, Atomic8Test::addLong17)); + mustEqual(35L, a.get(this)); + mustEqual(35L, aLongField); } /** @@ -361,12 +361,12 @@ public class Atomic8Test extends JSR166T * and updates with supplied function. */ public void testLongFieldUpdaterGetAndAccumulate() { - AtomicLongFieldUpdater a = aLongFieldUpdater(); - a.set(this, 1); - assertEquals(1L, a.getAndAccumulate(this, 2L, Long::sum)); - assertEquals(3L, a.getAndAccumulate(this, 3L, Long::sum)); - assertEquals(6L, a.get(this)); - assertEquals(6L, aLongField); + AtomicLongFieldUpdater a = aLongFieldUpdater(); + a.set(this, 1L); + mustEqual(1L, a.getAndAccumulate(this, 2L, Long::sum)); + mustEqual(3L, a.getAndAccumulate(this, 3L, Long::sum)); + mustEqual(6L, a.get(this)); + mustEqual(6L, aLongField); } /** @@ -374,12 +374,12 @@ public class Atomic8Test extends JSR166T * function and returns result. */ public void testLongFieldUpdaterAccumulateAndGet() { - AtomicLongFieldUpdater a = aLongFieldUpdater(); - a.set(this, 1); - assertEquals(7L, a.accumulateAndGet(this, 6L, Long::sum)); - assertEquals(10L, a.accumulateAndGet(this, 3L, Long::sum)); - assertEquals(10L, a.get(this)); - assertEquals(10L, aLongField); + AtomicLongFieldUpdater a = aLongFieldUpdater(); + a.set(this, 1L); + mustEqual(7L, a.accumulateAndGet(this, 6L, Long::sum)); + mustEqual(10L, a.accumulateAndGet(this, 3L, Long::sum)); + mustEqual(10L, a.get(this)); + mustEqual(10L, aLongField); } /** @@ -387,12 +387,12 @@ public class Atomic8Test extends JSR166T * result of supplied function */ public void testIntegerFieldUpdaterGetAndUpdate() { - AtomicIntegerFieldUpdater a = anIntFieldUpdater(); + AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); - assertEquals(1, a.getAndUpdate(this, Atomic8Test::addInt17)); - assertEquals(18, a.getAndUpdate(this, Atomic8Test::addInt17)); - assertEquals(35, a.get(this)); - assertEquals(35, anIntField); + mustEqual(1, a.getAndUpdate(this, Atomic8Test::addInt17)); + mustEqual(18, a.getAndUpdate(this, Atomic8Test::addInt17)); + mustEqual(35, a.get(this)); + mustEqual(35, anIntField); } /** @@ -400,12 +400,12 @@ public class Atomic8Test extends JSR166T * returns result. */ public void testIntegerFieldUpdaterUpdateAndGet() { - AtomicIntegerFieldUpdater a = anIntFieldUpdater(); + AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); - assertEquals(18, a.updateAndGet(this, Atomic8Test::addInt17)); - assertEquals(35, a.updateAndGet(this, Atomic8Test::addInt17)); - assertEquals(35, a.get(this)); - assertEquals(35, anIntField); + mustEqual(18, a.updateAndGet(this, Atomic8Test::addInt17)); + mustEqual(35, a.updateAndGet(this, Atomic8Test::addInt17)); + mustEqual(35, a.get(this)); + mustEqual(35, anIntField); } /** @@ -413,12 +413,12 @@ public class Atomic8Test extends JSR166T * and updates with supplied function. */ public void testIntegerFieldUpdaterGetAndAccumulate() { - AtomicIntegerFieldUpdater a = anIntFieldUpdater(); + AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); - assertEquals(1, a.getAndAccumulate(this, 2, Integer::sum)); - assertEquals(3, a.getAndAccumulate(this, 3, Integer::sum)); - assertEquals(6, a.get(this)); - assertEquals(6, anIntField); + mustEqual(1, a.getAndAccumulate(this, 2, Integer::sum)); + mustEqual(3, a.getAndAccumulate(this, 3, Integer::sum)); + mustEqual(6, a.get(this)); + mustEqual(6, anIntField); } /** @@ -426,12 +426,12 @@ public class Atomic8Test extends JSR166T * function and returns result. */ public void testIntegerFieldUpdaterAccumulateAndGet() { - AtomicIntegerFieldUpdater a = anIntFieldUpdater(); + AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); - assertEquals(7, a.accumulateAndGet(this, 6, Integer::sum)); - assertEquals(10, a.accumulateAndGet(this, 3, Integer::sum)); - assertEquals(10, a.get(this)); - assertEquals(10, anIntField); + mustEqual(7, a.accumulateAndGet(this, 6, Integer::sum)); + mustEqual(10, a.accumulateAndGet(this, 3, Integer::sum)); + mustEqual(10, a.get(this)); + mustEqual(10, anIntField); } /** @@ -439,12 +439,12 @@ public class Atomic8Test extends JSR166T * and updates result of supplied function */ public void testReferenceFieldUpdaterGetAndUpdate() { - AtomicReferenceFieldUpdater a = anIntegerFieldUpdater(); + AtomicReferenceFieldUpdater a = anItemFieldUpdater(); a.set(this, one); - assertEquals((Integer) 1, a.getAndUpdate(this, Atomic8Test::addInteger17)); - assertEquals((Integer) 18, a.getAndUpdate(this, Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.get(this)); - assertEquals((Integer) 35, anIntegerField); + mustEqual( 1, a.getAndUpdate(this, Atomic8Test::addItem17)); + mustEqual( 18, a.getAndUpdate(this, Atomic8Test::addItem17)); + mustEqual( 35, a.get(this)); + mustEqual( 35, anItemField); } /** @@ -452,12 +452,12 @@ public class Atomic8Test extends JSR166T * function and returns result. */ public void testReferenceFieldUpdaterUpdateAndGet() { - AtomicReferenceFieldUpdater a = anIntegerFieldUpdater(); + AtomicReferenceFieldUpdater a = anItemFieldUpdater(); a.set(this, one); - assertEquals((Integer) 18, a.updateAndGet(this, Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.updateAndGet(this, Atomic8Test::addInteger17)); - assertEquals((Integer) 35, a.get(this)); - assertEquals((Integer) 35, anIntegerField); + mustEqual( 18, a.updateAndGet(this, Atomic8Test::addItem17)); + mustEqual( 35, a.updateAndGet(this, Atomic8Test::addItem17)); + mustEqual( 35, a.get(this)); + mustEqual( 35, anItemField); } /** @@ -465,12 +465,12 @@ public class Atomic8Test extends JSR166T * with supplied function. */ public void testReferenceFieldUpdaterGetAndAccumulate() { - AtomicReferenceFieldUpdater a = anIntegerFieldUpdater(); + AtomicReferenceFieldUpdater a = anItemFieldUpdater(); a.set(this, one); - assertEquals((Integer) 1, a.getAndAccumulate(this, 2, Atomic8Test::sumInteger)); - assertEquals((Integer) 3, a.getAndAccumulate(this, 3, Atomic8Test::sumInteger)); - assertEquals((Integer) 6, a.get(this)); - assertEquals((Integer) 6, anIntegerField); + mustEqual( 1, a.getAndAccumulate(this, two, Atomic8Test::sumItem)); + mustEqual( 3, a.getAndAccumulate(this, three, Atomic8Test::sumItem)); + mustEqual( 6, a.get(this)); + mustEqual( 6, anItemField); } /** @@ -478,18 +478,19 @@ public class Atomic8Test extends JSR166T * supplied function and returns result. */ public void testReferenceFieldUpdaterAccumulateAndGet() { - AtomicReferenceFieldUpdater a = anIntegerFieldUpdater(); + AtomicReferenceFieldUpdater a = anItemFieldUpdater(); a.set(this, one); - assertEquals((Integer) 7, a.accumulateAndGet(this, 6, Atomic8Test::sumInteger)); - assertEquals((Integer) 10, a.accumulateAndGet(this, 3, Atomic8Test::sumInteger)); - assertEquals((Integer) 10, a.get(this)); - assertEquals((Integer) 10, anIntegerField); + mustEqual( 7, a.accumulateAndGet(this, six, Atomic8Test::sumItem)); + mustEqual( 10, a.accumulateAndGet(this, three, Atomic8Test::sumItem)); + mustEqual( 10, a.get(this)); + mustEqual( 10, anItemField); } /** * All Atomic getAndUpdate methods throw NullPointerException on * null function argument */ + @SuppressWarnings("unchecked") public void testGetAndUpdateNPE() { assertThrows( NullPointerException.class, @@ -501,12 +502,13 @@ public class Atomic8Test extends JSR166T () -> new AtomicReferenceArray(1).getAndUpdate(0, null), () -> aLongFieldUpdater().getAndUpdate(this, null), () -> anIntFieldUpdater().getAndUpdate(this, null), - () -> anIntegerFieldUpdater().getAndUpdate(this, null)); + () -> anItemFieldUpdater().getAndUpdate(this, null)); } /** * All Atomic updateAndGet methods throw NullPointerException on null function argument */ + @SuppressWarnings("unchecked") public void testUpdateAndGetNPE() { assertThrows( NullPointerException.class, @@ -518,13 +520,14 @@ public class Atomic8Test extends JSR166T () -> new AtomicReferenceArray(1).updateAndGet(0, null), () -> aLongFieldUpdater().updateAndGet(this, null), () -> anIntFieldUpdater().updateAndGet(this, null), - () -> anIntegerFieldUpdater().updateAndGet(this, null)); + () -> anItemFieldUpdater().updateAndGet(this, null)); } /** * All Atomic getAndAccumulate methods throw NullPointerException * on null function argument */ + @SuppressWarnings("unchecked") public void testGetAndAccumulateNPE() { assertThrows( NullPointerException.class, @@ -536,13 +539,14 @@ public class Atomic8Test extends JSR166T () -> new AtomicReferenceArray(1).getAndAccumulate(0, one, null), () -> aLongFieldUpdater().getAndAccumulate(this, 1L, null), () -> anIntFieldUpdater().getAndAccumulate(this, 1, null), - () -> anIntegerFieldUpdater().getAndAccumulate(this, one, null)); + () -> anItemFieldUpdater().getAndAccumulate(this, one, null)); } /** * All Atomic accumulateAndGet methods throw NullPointerException * on null function argument */ + @SuppressWarnings("unchecked") public void testAccumulateAndGetNPE() { assertThrows( NullPointerException.class, @@ -554,7 +558,7 @@ public class Atomic8Test extends JSR166T () -> new AtomicReferenceArray(1).accumulateAndGet(0, one, null), () -> aLongFieldUpdater().accumulateAndGet(this, 1L, null), () -> anIntFieldUpdater().accumulateAndGet(this, 1, null), - () -> anIntegerFieldUpdater().accumulateAndGet(this, one, null)); + () -> anItemFieldUpdater().accumulateAndGet(this, one, null)); } /** @@ -562,11 +566,12 @@ public class Atomic8Test extends JSR166T * instances of the class passed to the newUpdater call will * result in a ClassCastException being thrown. */ + @SuppressWarnings("unchecked") public void testFieldUpdaters_ClassCastException() { // Use raw types to allow passing wrong object type, provoking CCE final AtomicLongFieldUpdater longUpdater = aLongFieldUpdater(); final AtomicIntegerFieldUpdater intUpdater = anIntFieldUpdater(); - final AtomicReferenceFieldUpdater refUpdater = anIntegerFieldUpdater(); + final AtomicReferenceFieldUpdater refUpdater = anItemFieldUpdater(); for (Object x : new Object[]{ new Object(), null }) { assertThrows( ClassCastException.class, @@ -576,7 +581,7 @@ public class Atomic8Test extends JSR166T () -> longUpdater.set(x, 17L), () -> intUpdater.set(x, 17), - () -> refUpdater.set(x, (Integer) 17), + () -> refUpdater.set(x, new Item(17)), () -> longUpdater.addAndGet(x, 17L), () -> intUpdater.addAndGet(x, 17), @@ -587,7 +592,7 @@ public class Atomic8Test extends JSR166T () -> longUpdater.compareAndSet(x, 17L, 42L), () -> intUpdater.compareAndSet(x, 17, 42), - () -> refUpdater.compareAndSet(x, (Integer) 17, (Integer) 42)); + () -> refUpdater.compareAndSet(x, 17, fortytwo)); } }