13 |
|
|
14 |
|
public class AtomicBooleanTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
16 |
< |
junit.textui.TestRunner.run(suite()); |
16 |
> |
main(suite(), args); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(AtomicBooleanTest.class); |
97 |
|
*/ |
98 |
|
public void testWeakCompareAndSet() { |
99 |
|
AtomicBoolean ai = new AtomicBoolean(true); |
100 |
< |
while (!ai.weakCompareAndSet(true, false)); |
100 |
> |
do {} while (!ai.weakCompareAndSet(true, false)); |
101 |
|
assertFalse(ai.get()); |
102 |
< |
while (!ai.weakCompareAndSet(false, false)); |
102 |
> |
do {} while (!ai.weakCompareAndSet(false, false)); |
103 |
|
assertFalse(ai.get()); |
104 |
< |
while (!ai.weakCompareAndSet(false, true)); |
104 |
> |
do {} while (!ai.weakCompareAndSet(false, true)); |
105 |
|
assertTrue(ai.get()); |
106 |
|
} |
107 |
|
|
109 |
|
* getAndSet returns previous value and sets to given value |
110 |
|
*/ |
111 |
|
public void testGetAndSet() { |
112 |
< |
AtomicBoolean ai = new AtomicBoolean(true); |
113 |
< |
assertEquals(true, ai.getAndSet(false)); |
114 |
< |
assertEquals(false, ai.getAndSet(false)); |
115 |
< |
assertEquals(false, ai.getAndSet(true)); |
116 |
< |
assertTrue(ai.get()); |
112 |
> |
AtomicBoolean ai = new AtomicBoolean(); |
113 |
> |
boolean[] booleans = { false, true }; |
114 |
> |
for (boolean before : booleans) |
115 |
> |
for (boolean after : booleans) { |
116 |
> |
ai.set(before); |
117 |
> |
assertEquals(before, ai.getAndSet(after)); |
118 |
> |
assertEquals(after, ai.get()); |
119 |
> |
} |
120 |
|
} |
121 |
|
|
122 |
|
/** |
123 |
< |
* a deserialized serialized atomic holds same value |
123 |
> |
* a deserialized/reserialized atomic holds same value |
124 |
|
*/ |
125 |
|
public void testSerialization() throws Exception { |
126 |
|
AtomicBoolean x = new AtomicBoolean(); |