17 |
|
return new TestSuite(AtomicLongTest.class); |
18 |
|
} |
19 |
|
|
20 |
+ |
/** |
21 |
+ |
* |
22 |
+ |
*/ |
23 |
|
public void testConstructor(){ |
24 |
|
AtomicLong ai = new AtomicLong(1); |
25 |
|
assertEquals(1,ai.get()); |
26 |
|
} |
27 |
|
|
28 |
+ |
/** |
29 |
+ |
* |
30 |
+ |
*/ |
31 |
|
public void testConstructor2(){ |
32 |
|
AtomicLong ai = new AtomicLong(); |
33 |
|
assertEquals(0,ai.get()); |
34 |
|
} |
35 |
|
|
36 |
+ |
/** |
37 |
+ |
* |
38 |
+ |
*/ |
39 |
|
public void testGetSet(){ |
40 |
|
AtomicLong ai = new AtomicLong(1); |
41 |
|
assertEquals(1,ai.get()); |
45 |
|
assertEquals(-3,ai.get()); |
46 |
|
|
47 |
|
} |
48 |
+ |
/** |
49 |
+ |
* |
50 |
+ |
*/ |
51 |
|
public void testCompareAndSet(){ |
52 |
|
AtomicLong ai = new AtomicLong(1); |
53 |
|
assertTrue(ai.compareAndSet(1,2)); |
59 |
|
assertEquals(7,ai.get()); |
60 |
|
} |
61 |
|
|
62 |
+ |
/** |
63 |
+ |
* |
64 |
+ |
*/ |
65 |
|
public void testWeakCompareAndSet(){ |
66 |
|
AtomicLong ai = new AtomicLong(1); |
67 |
|
while(!ai.weakCompareAndSet(1,2)); |
71 |
|
assertEquals(7,ai.get()); |
72 |
|
} |
73 |
|
|
74 |
+ |
/** |
75 |
+ |
* |
76 |
+ |
*/ |
77 |
|
public void testGetAndSet(){ |
78 |
|
AtomicLong ai = new AtomicLong(1); |
79 |
|
assertEquals(1,ai.getAndSet(0)); |
81 |
|
assertEquals(-10,ai.getAndSet(1)); |
82 |
|
} |
83 |
|
|
84 |
+ |
/** |
85 |
+ |
* |
86 |
+ |
*/ |
87 |
|
public void testGetAndAdd(){ |
88 |
|
AtomicLong ai = new AtomicLong(1); |
89 |
|
assertEquals(1,ai.getAndAdd(2)); |
92 |
|
assertEquals(-1,ai.get()); |
93 |
|
} |
94 |
|
|
95 |
+ |
/** |
96 |
+ |
* |
97 |
+ |
*/ |
98 |
|
public void testGetAndDecrement(){ |
99 |
|
AtomicLong ai = new AtomicLong(1); |
100 |
|
assertEquals(1,ai.getAndDecrement()); |
102 |
|
assertEquals(-1,ai.getAndDecrement()); |
103 |
|
} |
104 |
|
|
105 |
+ |
/** |
106 |
+ |
* |
107 |
+ |
*/ |
108 |
|
public void testGetAndIncrement(){ |
109 |
|
AtomicLong ai = new AtomicLong(1); |
110 |
|
assertEquals(1,ai.getAndIncrement()); |
116 |
|
assertEquals(1,ai.get()); |
117 |
|
} |
118 |
|
|
119 |
+ |
/** |
120 |
+ |
* |
121 |
+ |
*/ |
122 |
|
public void testAddAndGet(){ |
123 |
|
AtomicLong ai = new AtomicLong(1); |
124 |
|
assertEquals(3,ai.addAndGet(2)); |
127 |
|
assertEquals(-1,ai.get()); |
128 |
|
} |
129 |
|
|
130 |
+ |
/** |
131 |
+ |
* |
132 |
+ |
*/ |
133 |
|
public void testDecrementAndGet(){ |
134 |
|
AtomicLong ai = new AtomicLong(1); |
135 |
|
assertEquals(0,ai.decrementAndGet()); |
138 |
|
assertEquals(-2,ai.get()); |
139 |
|
} |
140 |
|
|
141 |
+ |
/** |
142 |
+ |
* |
143 |
+ |
*/ |
144 |
|
public void testIncrementAndGet(){ |
145 |
|
AtomicLong ai = new AtomicLong(1); |
146 |
|
assertEquals(2,ai.incrementAndGet()); |
152 |
|
assertEquals(1,ai.get()); |
153 |
|
} |
154 |
|
|
155 |
+ |
/** |
156 |
+ |
* |
157 |
+ |
*/ |
158 |
|
public void testSerialization() { |
159 |
|
AtomicLong l = new AtomicLong(); |
160 |
|
|
170 |
|
AtomicLong r = (AtomicLong) in.readObject(); |
171 |
|
assertEquals(l.get(), r.get()); |
172 |
|
} catch(Exception e){ |
173 |
< |
e.printStackTrace(); |
135 |
< |
fail("unexpected exception"); |
173 |
> |
unexpectedException(); |
174 |
|
} |
175 |
|
} |
176 |
|
|