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 |
– |
AtomicLongFieldUpdater.newUpdater |
43 |
– |
(AtomicLongFieldUpdaterTest.class, "protectedField"); |
44 |
– |
this.protectedField = 1; |
45 |
– |
assertTrue(a.compareAndSet(this, 1, 2)); |
46 |
– |
assertTrue(a.compareAndSet(this, 2, -4)); |
47 |
– |
assertEquals(-4, a.get(this)); |
48 |
– |
assertFalse(a.compareAndSet(this, -5, 7)); |
49 |
– |
assertEquals(-4, a.get(this)); |
50 |
– |
assertTrue(a.compareAndSet(this, -4, 7)); |
51 |
– |
assertEquals(7, a.get(this)); |
52 |
– |
} |
53 |
– |
} |
54 |
– |
|
55 |
– |
static class UnrelatedClass { |
56 |
– |
public void checkPackageAccess(AtomicLongFieldUpdaterTest obj) { |
57 |
– |
obj.x = 72L; |
58 |
– |
AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = |
59 |
– |
AtomicLongFieldUpdater.newUpdater |
60 |
– |
(AtomicLongFieldUpdaterTest.class, "x"); |
61 |
– |
assertEquals(72L, a.get(obj)); |
62 |
– |
assertTrue(a.compareAndSet(obj, 72L, 73L)); |
63 |
– |
assertEquals(73L, a.get(obj)); |
64 |
– |
} |
65 |
– |
|
66 |
– |
public void checkPrivateAccess(AtomicLongFieldUpdaterTest obj) { |
67 |
– |
try { |
68 |
– |
AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = |
69 |
– |
AtomicLongFieldUpdater.newUpdater |
70 |
– |
(AtomicLongFieldUpdaterTest.class, "privateField"); |
71 |
– |
throw new AssertionError("should throw"); |
72 |
– |
} catch (RuntimeException success) { |
73 |
– |
assertNotNull(success.getCause()); |
74 |
– |
} |
75 |
– |
} |
76 |
– |
} |
77 |
– |
|
27 |
|
AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> updaterFor(String fieldName) { |
28 |
|
return AtomicLongFieldUpdater.newUpdater |
29 |
|
(AtomicLongFieldUpdaterTest.class, fieldName); |
65 |
|
* construction using private field from subclass throws RuntimeException |
66 |
|
*/ |
67 |
|
public void testPrivateFieldInSubclass() { |
68 |
< |
AtomicLongFieldUpdaterTestSubclass s = |
69 |
< |
new AtomicLongFieldUpdaterTestSubclass(); |
121 |
< |
s.checkPrivateAccess(); |
68 |
> |
new NonNestmates.AtomicLongFieldUpdaterTestSubclass() |
69 |
> |
.checkPrivateAccess(); |
70 |
|
} |
71 |
|
|
72 |
|
/** |
74 |
|
* private access is not |
75 |
|
*/ |
76 |
|
public void testUnrelatedClassAccess() { |
77 |
< |
new UnrelatedClass().checkPackageAccess(this); |
78 |
< |
new UnrelatedClass().checkPrivateAccess(this); |
77 |
> |
new NonNestmates().checkPackageAccess(this); |
78 |
> |
new NonNestmates().checkPrivateAccess(this); |
79 |
|
} |
80 |
|
|
81 |
|
/** |
144 |
|
* equal to expected else fails |
145 |
|
*/ |
146 |
|
public void testCompareAndSetProtectedInSubclass() { |
147 |
< |
AtomicLongFieldUpdaterTestSubclass s = |
148 |
< |
new AtomicLongFieldUpdaterTestSubclass(); |
201 |
< |
s.checkCompareAndSetProtectedSub(); |
147 |
> |
new NonNestmates.AtomicLongFieldUpdaterTestSubclass() |
148 |
> |
.checkCompareAndSetProtectedSub(); |
149 |
|
} |
150 |
|
|
151 |
|
/** |