8 |
|
|
9 |
|
import static org.junit.Assert.assertEquals; |
10 |
|
import static org.junit.Assert.assertNotNull; |
11 |
– |
import static org.junit.Assert.assertNull; |
11 |
|
import static org.junit.Assert.assertSame; |
12 |
|
import static org.junit.Assert.assertTrue; |
13 |
|
|
16 |
|
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; |
17 |
|
|
18 |
|
/** |
19 |
< |
* This helper class and its subclasses are deliberately not contained |
20 |
< |
* textually in the test source files that use them, to avoid making |
21 |
< |
* them nestmates, which affects access rules (see JEP 181). |
19 |
> |
* This source file contains test code deliberately not contained in |
20 |
> |
* the same source file as the tests that use them, to avoid making |
21 |
> |
* them nestmates, which affects accessibility rules (see JEP 181). |
22 |
|
*/ |
23 |
|
class NonNestmates { |
24 |
|
|
43 |
|
} |
44 |
|
|
45 |
|
public void checkPackageAccess(AtomicReferenceFieldUpdaterTest obj) { |
46 |
< |
Integer one = new Integer(1); |
47 |
< |
Integer two = new Integer(2); |
46 |
> |
Item one = new Item(1); |
47 |
> |
Item two = new Item(2); |
48 |
|
obj.x = one; |
49 |
< |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest,Integer> a = |
49 |
> |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest,Item> a = |
50 |
|
AtomicReferenceFieldUpdater.newUpdater( |
51 |
< |
AtomicReferenceFieldUpdaterTest.class, Integer.class, "x"); |
51 |
> |
AtomicReferenceFieldUpdaterTest.class, Item.class, "x"); |
52 |
|
assertSame(one, a.get(obj)); |
53 |
|
assertTrue(a.compareAndSet(obj, one, two)); |
54 |
|
assertSame(two, a.get(obj)); |
162 |
|
} |
163 |
|
|
164 |
|
public void checkCompareAndSetProtectedSub() { |
165 |
< |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest,Integer> a = |
165 |
> |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest,Item> a = |
166 |
|
AtomicReferenceFieldUpdater.newUpdater( |
167 |
|
AtomicReferenceFieldUpdaterTest.class, |
168 |
< |
Integer.class, "protectedField"); |
168 |
> |
Item.class, "protectedField"); |
169 |
|
this.protectedField = one; |
170 |
|
assertTrue(a.compareAndSet(this, one, two)); |
171 |
< |
assertTrue(a.compareAndSet(this, two, m4)); |
172 |
< |
assertSame(m4, a.get(this)); |
173 |
< |
assertFalse(a.compareAndSet(this, m5, seven)); |
171 |
> |
assertTrue(a.compareAndSet(this, two, minusFour)); |
172 |
> |
assertSame(minusFour, a.get(this)); |
173 |
> |
assertFalse(a.compareAndSet(this, minusFive, seven)); |
174 |
|
assertNotSame(seven, a.get(this)); |
175 |
< |
assertTrue(a.compareAndSet(this, m4, seven)); |
175 |
> |
assertTrue(a.compareAndSet(this, minusFour, seven)); |
176 |
|
assertSame(seven, a.get(this)); |
177 |
|
} |
178 |
|
} |