ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicLongFieldUpdaterTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicLongFieldUpdaterTest.java (file contents):
Revision 1.28 by jsr166, Wed Dec 31 19:21:20 2014 UTC vs.
Revision 1.34 by jsr166, Wed Sep 20 00:59:17 2017 UTC

# Line 13 | Line 13 | import junit.framework.TestSuite;
13  
14   public class AtomicLongFieldUpdaterTest extends JSR166TestCase {
15      volatile long x = 0;
16 <    int z;
16 >    protected volatile long protectedField;
17 >    private volatile long privateField;
18      long w;
19 <
19 >    float z;
20      public static void main(String[] args) {
21 <        junit.textui.TestRunner.run(suite());
21 >        main(suite(), args);
22      }
23      public static Test suite() {
24          return new TestSuite(AtomicLongFieldUpdaterTest.class);
# Line 61 | Line 62 | public class AtomicLongFieldUpdaterTest
62      }
63  
64      /**
65 +     * construction using private field from subclass throws RuntimeException
66 +     */
67 +    public void testPrivateFieldInSubclass() {
68 +        new NonNestmates.AtomicLongFieldUpdaterTestSubclass()
69 +            .checkPrivateAccess();
70 +    }
71 +
72 +    /**
73 +     * construction from unrelated class; package access is allowed,
74 +     * private access is not
75 +     */
76 +    public void testUnrelatedClassAccess() {
77 +        new NonNestmates().checkPackageAccess(this);
78 +        new NonNestmates().checkPrivateAccess(this);
79 +    }
80 +
81 +    /**
82       * get returns the last value set or assigned
83       */
84      public void testGetSet() {
# Line 105 | Line 123 | public class AtomicLongFieldUpdaterTest
123      }
124  
125      /**
126 +     * compareAndSet succeeds in changing protected field value if
127 +     * equal to expected else fails
128 +     */
129 +    public void testCompareAndSetProtected() {
130 +        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
131 +        a = updaterFor("protectedField");
132 +        protectedField = 1;
133 +        assertTrue(a.compareAndSet(this, 1, 2));
134 +        assertTrue(a.compareAndSet(this, 2, -4));
135 +        assertEquals(-4, a.get(this));
136 +        assertFalse(a.compareAndSet(this, -5, 7));
137 +        assertEquals(-4, a.get(this));
138 +        assertTrue(a.compareAndSet(this, -4, 7));
139 +        assertEquals(7, a.get(this));
140 +    }
141 +
142 +    /**
143 +     * compareAndSet succeeds in changing protected field value if
144 +     * equal to expected else fails
145 +     */
146 +    public void testCompareAndSetProtectedInSubclass() {
147 +        new NonNestmates.AtomicLongFieldUpdaterTestSubclass()
148 +            .checkCompareAndSetProtectedSub();
149 +    }
150 +
151 +    /**
152       * compareAndSet in one thread enables another waiting for value
153       * to succeed
154       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines