test-ng/tests/org/openjdk/tests/java/util/functions/LongUnaryOperatorTest.java

Print this page
rev 5834 : Rename compareAndSet methods, add updateAndGet/getAndUpdate to AtomicReference, add tests
Reviewed-by: briangoetz,smarks,mduigo
Contributed-by: Jim Gish <jim.gish@oracle.com>

*** 22,31 **** --- 22,32 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.openjdk.tests.java.util.functions; + import java.util.concurrent.atomic.AtomicLong; import java.util.functions.LongUnaryOperator; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeClass;
*** 52,61 **** --- 53,72 ---- long expResult = 3L; long result = instance.operate(operand); assertEquals(result, expResult); } + public void testUpdateOps() { + AtomicLong atomLong = new AtomicLong(3); + // make sure we the updated value is returned + assertEquals( atomLong.updateAndGet(x -> x + 1), 4 ); + // then the previous value is returned + assertEquals( atomLong.getAndUpdate(x -> x + 1), 4 ); + // finally, verify that the update was successful + assertEquals( atomLong.get(), 5 ); + }; + public class LongUnaryOperatorImpl implements LongUnaryOperator { public long operate(long operand) { // inc by 3 return operand + 3L;