17 |
|
return new TestSuite(AtomicReferenceTest.class); |
18 |
|
} |
19 |
|
|
20 |
+ |
/** |
21 |
+ |
* |
22 |
+ |
*/ |
23 |
|
public void testConstructor(){ |
24 |
|
AtomicReference ai = new AtomicReference(one); |
25 |
|
assertEquals(one,ai.get()); |
26 |
|
} |
27 |
|
|
28 |
+ |
/** |
29 |
+ |
* |
30 |
+ |
*/ |
31 |
|
public void testConstructor2(){ |
32 |
|
AtomicReference ai = new AtomicReference(); |
33 |
|
assertNull(ai.get()); |
34 |
|
} |
35 |
|
|
36 |
+ |
/** |
37 |
+ |
* |
38 |
+ |
*/ |
39 |
|
public void testGetSet(){ |
40 |
|
AtomicReference ai = new AtomicReference(one); |
41 |
|
assertEquals(one,ai.get()); |
45 |
|
assertEquals(m3,ai.get()); |
46 |
|
|
47 |
|
} |
48 |
+ |
/** |
49 |
+ |
* |
50 |
+ |
*/ |
51 |
|
public void testCompareAndSet(){ |
52 |
|
AtomicReference ai = new AtomicReference(one); |
53 |
|
assertTrue(ai.compareAndSet(one,two)); |
59 |
|
assertEquals(seven,ai.get()); |
60 |
|
} |
61 |
|
|
62 |
+ |
/** |
63 |
+ |
* |
64 |
+ |
*/ |
65 |
|
public void testWeakCompareAndSet(){ |
66 |
|
AtomicReference ai = new AtomicReference(one); |
67 |
|
while(!ai.weakCompareAndSet(one,two)); |
71 |
|
assertEquals(seven,ai.get()); |
72 |
|
} |
73 |
|
|
74 |
+ |
/** |
75 |
+ |
* |
76 |
+ |
*/ |
77 |
|
public void testGetAndSet(){ |
78 |
|
AtomicReference ai = new AtomicReference(one); |
79 |
|
assertEquals(one,ai.getAndSet(zero)); |
81 |
|
assertEquals(m10,ai.getAndSet(one)); |
82 |
|
} |
83 |
|
|
84 |
+ |
/** |
85 |
+ |
* |
86 |
+ |
*/ |
87 |
|
public void testSerialization() { |
88 |
|
AtomicReference l = new AtomicReference(); |
89 |
|
|
99 |
|
AtomicReference r = (AtomicReference) in.readObject(); |
100 |
|
assertEquals(l.get(), r.get()); |
101 |
|
} catch(Exception e){ |
102 |
< |
e.printStackTrace(); |
82 |
< |
fail("unexpected exception"); |
102 |
> |
unexpectedException(); |
103 |
|
} |
104 |
|
} |
105 |
|
|