6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.AtomicInteger; |
10 |
|
|
11 |
+ |
import junit.framework.Test; |
12 |
+ |
import junit.framework.TestSuite; |
13 |
+ |
|
14 |
|
public class AtomicIntegerTest 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(AtomicIntegerTest.class); |
93 |
|
assertTrue(ai.compareAndSet(1, 2)); |
94 |
|
t.join(LONG_DELAY_MS); |
95 |
|
assertFalse(t.isAlive()); |
96 |
< |
assertEquals(ai.get(), 3); |
96 |
> |
assertEquals(3, ai.get()); |
97 |
|
} |
98 |
|
|
99 |
|
/** |
102 |
|
*/ |
103 |
|
public void testWeakCompareAndSet() { |
104 |
|
AtomicInteger ai = new AtomicInteger(1); |
105 |
< |
while (!ai.weakCompareAndSet(1, 2)); |
106 |
< |
while (!ai.weakCompareAndSet(2, -4)); |
105 |
> |
do {} while (!ai.weakCompareAndSet(1, 2)); |
106 |
> |
do {} while (!ai.weakCompareAndSet(2, -4)); |
107 |
|
assertEquals(-4, ai.get()); |
108 |
< |
while (!ai.weakCompareAndSet(-4, 7)); |
108 |
> |
do {} while (!ai.weakCompareAndSet(-4, 7)); |
109 |
|
assertEquals(7, ai.get()); |
110 |
|
} |
111 |
|
|
196 |
|
public void testSerialization() throws Exception { |
197 |
|
AtomicInteger x = new AtomicInteger(); |
198 |
|
AtomicInteger y = serialClone(x); |
199 |
< |
assertTrue(x != y); |
199 |
> |
assertNotSame(x, y); |
200 |
|
x.set(22); |
201 |
|
AtomicInteger z = serialClone(x); |
202 |
|
assertEquals(22, x.get()); |
212 |
|
assertEquals("0", ai.toString()); |
213 |
|
for (int x : VALUES) { |
214 |
|
ai.set(x); |
215 |
< |
assertEquals(ai.toString(), Integer.toString(x)); |
215 |
> |
assertEquals(Integer.toString(x), ai.toString()); |
216 |
|
} |
217 |
|
} |
218 |
|
|