95 |
|
* repeated weakCompareAndSet succeeds in changing value when equal |
96 |
|
* to expected |
97 |
|
*/ |
98 |
+ |
@SuppressWarnings("deprecation") |
99 |
|
public void testWeakCompareAndSet() { |
100 |
|
AtomicBoolean ai = new AtomicBoolean(true); |
101 |
|
do {} while (!ai.weakCompareAndSet(true, false)); |
110 |
|
* getAndSet returns previous value and sets to given value |
111 |
|
*/ |
112 |
|
public void testGetAndSet() { |
113 |
< |
AtomicBoolean ai = new AtomicBoolean(true); |
114 |
< |
assertEquals(true, ai.getAndSet(false)); |
115 |
< |
assertEquals(false, ai.getAndSet(false)); |
116 |
< |
assertEquals(false, ai.getAndSet(true)); |
117 |
< |
assertTrue(ai.get()); |
113 |
> |
AtomicBoolean ai = new AtomicBoolean(); |
114 |
> |
boolean[] booleans = { false, true }; |
115 |
> |
for (boolean before : booleans) |
116 |
> |
for (boolean after : booleans) { |
117 |
> |
ai.set(before); |
118 |
> |
assertEquals(before, ai.getAndSet(after)); |
119 |
> |
assertEquals(after, ai.get()); |
120 |
> |
} |
121 |
|
} |
122 |
|
|
123 |
|
/** |
124 |
< |
* a deserialized serialized atomic holds same value |
124 |
> |
* a deserialized/reserialized atomic holds same value |
125 |
|
*/ |
126 |
|
public void testSerialization() throws Exception { |
127 |
|
AtomicBoolean x = new AtomicBoolean(); |