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.30 by dl, Sun Nov 8 15:34:01 2015 UTC vs.
Revision 1.34 by jsr166, Wed Sep 20 00:59:17 2017 UTC

# Line 24 | Line 24 | public class AtomicLongFieldUpdaterTest
24          return new TestSuite(AtomicLongFieldUpdaterTest.class);
25      }
26  
27    // for testing subclass access
28    static class AtomicLongFieldUpdaterTestSubclass extends AtomicLongFieldUpdaterTest {
29        public void checkPrivateAccess() {
30            try {
31                AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
32                    AtomicLongFieldUpdater.newUpdater
33                    (AtomicLongFieldUpdaterTest.class, "privateField");
34                shouldThrow();
35            } catch (RuntimeException success) {
36                assertNotNull(success.getCause());
37            }
38        }
39
40        public void checkCompareAndSetProtectedSub() {
41            AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
42            a = updaterFor("protectedField");
43            protectedField = 1;
44            assertTrue(a.compareAndSet(this, 1, 2));
45            assertTrue(a.compareAndSet(this, 2, -4));
46            assertEquals(-4, a.get(this));
47            assertFalse(a.compareAndSet(this, -5, 7));
48            assertEquals(-4, a.get(this));
49            assertTrue(a.compareAndSet(this, -4, 7));
50            assertEquals(7, a.get(this));
51        }
52    }
53
54    static class UnrelatedClass {
55        public void checkPrivateAccess() {
56            Exception ex = null;
57            try {
58                AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
59                    AtomicLongFieldUpdater.newUpdater
60                    (AtomicLongFieldUpdaterTest.class, "x");
61            } catch (RuntimeException rex) {
62                ex = rex;
63            }
64            if (ex != null) throw new Error();
65        }
66    }
67
27      AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> updaterFor(String fieldName) {
28          return AtomicLongFieldUpdater.newUpdater
29              (AtomicLongFieldUpdaterTest.class, fieldName);
# Line 106 | Line 65 | public class AtomicLongFieldUpdaterTest
65       * construction using private field from subclass throws RuntimeException
66       */
67      public void testPrivateFieldInSubclass() {
68 <        AtomicLongFieldUpdaterTestSubclass s =
69 <            new AtomicLongFieldUpdaterTestSubclass();
111 <        s.checkPrivateAccess();
68 >        new NonNestmates.AtomicLongFieldUpdaterTestSubclass()
69 >            .checkPrivateAccess();
70      }
71  
72      /**
73 <     * construction from unrelated class throws RuntimeException
73 >     * construction from unrelated class; package access is allowed,
74 >     * private access is not
75       */
76      public void testUnrelatedClassAccess() {
77 <        UnrelatedClass s = new UnrelatedClass();
78 <        s.checkPrivateAccess();
77 >        new NonNestmates().checkPackageAccess(this);
78 >        new NonNestmates().checkPrivateAccess(this);
79      }
80  
81      /**
# Line 185 | Line 144 | public class AtomicLongFieldUpdaterTest
144       * equal to expected else fails
145       */
146      public void testCompareAndSetProtectedInSubclass() {
147 <        AtomicLongFieldUpdaterTestSubclass s =
148 <            new AtomicLongFieldUpdaterTestSubclass();
190 <        s.checkCompareAndSetProtectedSub();
147 >        new NonNestmates.AtomicLongFieldUpdaterTestSubclass()
148 >            .checkCompareAndSetProtectedSub();
149      }
150  
151      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines