11 |
|
import java.io.*; |
12 |
|
import java.util.*; |
13 |
|
|
14 |
< |
public class AtomicReferenceArrayTest extends JSR166TestCase |
15 |
< |
{ |
14 |
> |
public class AtomicReferenceArrayTest extends JSR166TestCase { |
15 |
|
public static void main (String[] args) { |
16 |
|
junit.textui.TestRunner.run (suite()); |
17 |
|
} |
22 |
|
/** |
23 |
|
* constructor creates array of given size with all elements null |
24 |
|
*/ |
25 |
< |
public void testConstructor(){ |
25 |
> |
public void testConstructor() { |
26 |
|
AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(SIZE); |
27 |
|
for (int i = 0; i < SIZE; ++i) { |
28 |
|
assertNull(ai.get(i)); |
36 |
|
try { |
37 |
|
Integer[] a = null; |
38 |
|
AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a); |
39 |
+ |
shouldThrow(); |
40 |
|
} catch (NullPointerException success) { |
41 |
– |
} catch (Exception ex) { |
42 |
– |
unexpectedException(); |
43 |
– |
} |
41 |
|
} |
42 |
|
|
43 |
|
/** |
55 |
|
/** |
56 |
|
* get and set for out of bound indices throw IndexOutOfBoundsException |
57 |
|
*/ |
58 |
< |
public void testIndexing(){ |
58 |
> |
public void testIndexing() { |
59 |
|
AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(SIZE); |
60 |
|
try { |
61 |
|
ai.get(SIZE); |
62 |
< |
} catch (IndexOutOfBoundsException success){ |
62 |
> |
shouldThrow(); |
63 |
> |
} catch (IndexOutOfBoundsException success) { |
64 |
|
} |
65 |
|
try { |
66 |
|
ai.get(-1); |
67 |
< |
} catch (IndexOutOfBoundsException success){ |
67 |
> |
shouldThrow(); |
68 |
> |
} catch (IndexOutOfBoundsException success) { |
69 |
|
} |
70 |
|
try { |
71 |
|
ai.set(SIZE, null); |
72 |
< |
} catch (IndexOutOfBoundsException success){ |
72 |
> |
shouldThrow(); |
73 |
> |
} catch (IndexOutOfBoundsException success) { |
74 |
|
} |
75 |
|
try { |
76 |
|
ai.set(-1, null); |
77 |
< |
} catch (IndexOutOfBoundsException success){ |
77 |
> |
shouldThrow(); |
78 |
> |
} catch (IndexOutOfBoundsException success) { |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
|
/** |
83 |
|
* get returns the last value set at index |
84 |
|
*/ |
85 |
< |
public void testGetSet(){ |
85 |
> |
public void testGetSet() { |
86 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
87 |
|
for (int i = 0; i < SIZE; ++i) { |
88 |
|
ai.set(i, one); |
97 |
|
/** |
98 |
|
* get returns the last value lazySet at index by same thread |
99 |
|
*/ |
100 |
< |
public void testGetLazySet(){ |
100 |
> |
public void testGetLazySet() { |
101 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
102 |
|
for (int i = 0; i < SIZE; ++i) { |
103 |
|
ai.lazySet(i, one); |
112 |
|
/** |
113 |
|
* compareAndSet succeeds in changing value if equal to expected else fails |
114 |
|
*/ |
115 |
< |
public void testCompareAndSet(){ |
115 |
> |
public void testCompareAndSet() { |
116 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
117 |
|
for (int i = 0; i < SIZE; ++i) { |
118 |
|
ai.set(i, one); |
153 |
|
* repeated weakCompareAndSet succeeds in changing value when equal |
154 |
|
* to expected |
155 |
|
*/ |
156 |
< |
public void testWeakCompareAndSet(){ |
156 |
> |
public void testWeakCompareAndSet() { |
157 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
158 |
|
for (int i = 0; i < SIZE; ++i) { |
159 |
|
ai.set(i, one); |
168 |
|
/** |
169 |
|
* getAndSet returns previous value and sets to given value at given index |
170 |
|
*/ |
171 |
< |
public void testGetAndSet(){ |
171 |
> |
public void testGetAndSet() { |
172 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
173 |
|
for (int i = 0; i < SIZE; ++i) { |
174 |
|
ai.set(i, one); |
200 |
|
for (int i = 0; i < SIZE; ++i) { |
201 |
|
assertEquals(r.get(i), l.get(i)); |
202 |
|
} |
203 |
< |
} catch (Exception e){ |
203 |
> |
} catch (Exception e) { |
204 |
|
unexpectedException(); |
205 |
|
} |
206 |
|
} |