ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/Atomic8Test.java
Revision: 1.7
Committed: Sat Sep 24 12:54:31 2016 UTC (7 years, 7 months ago) by jsr166
Branch: MAIN
Changes since 1.6: +43 -45 lines
Log Message:
cosmetic improvements

File Contents

# User Rev Content
1 dl 1.1 /*
2     * Written by Doug Lea and Martin Buchholz with assistance from
3     * members of JCP JSR-166 Expert Group and released to the public
4     * domain, as explained at
5     * http://creativecommons.org/publicdomain/zero/1.0/
6     */
7    
8 jsr166 1.3 import java.util.concurrent.atomic.AtomicInteger;
9     import java.util.concurrent.atomic.AtomicIntegerArray;
10     import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
11     import java.util.concurrent.atomic.AtomicLong;
12     import java.util.concurrent.atomic.AtomicLongArray;
13     import java.util.concurrent.atomic.AtomicLongFieldUpdater;
14     import java.util.concurrent.atomic.AtomicReference;
15     import java.util.concurrent.atomic.AtomicReferenceArray;
16     import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
17    
18     import junit.framework.Test;
19     import junit.framework.TestSuite;
20 dl 1.1
21 jsr166 1.7 /**
22     * Tests of atomic class methods accepting lambdas introduced in JDK8.
23     */
24 dl 1.1 public class Atomic8Test extends JSR166TestCase {
25    
26     public static void main(String[] args) {
27 jsr166 1.5 main(suite(), args);
28 dl 1.1 }
29     public static Test suite() {
30     return new TestSuite(Atomic8Test.class);
31     }
32    
33     static long addLong17(long x) { return x + 17; }
34     static int addInt17(int x) { return x + 17; }
35     static Integer addInteger17(Integer x) {
36 jsr166 1.7 return x.intValue() + 17;
37 dl 1.1 }
38     static Integer sumInteger(Integer x, Integer y) {
39 jsr166 1.7 return x.intValue() + y.intValue();
40 dl 1.1 }
41    
42     volatile long aLongField;
43     volatile int anIntField;
44     volatile Integer anIntegerField;
45    
46 jsr166 1.2 AtomicLongFieldUpdater aLongFieldUpdater() {
47     return AtomicLongFieldUpdater.newUpdater
48     (Atomic8Test.class, "aLongField");
49     }
50    
51     AtomicIntegerFieldUpdater anIntFieldUpdater() {
52     return AtomicIntegerFieldUpdater.newUpdater
53     (Atomic8Test.class, "anIntField");
54     }
55    
56     AtomicReferenceFieldUpdater<Atomic8Test,Integer> anIntegerFieldUpdater() {
57     return AtomicReferenceFieldUpdater.newUpdater
58     (Atomic8Test.class, Integer.class, "anIntegerField");
59     }
60    
61 dl 1.1 /**
62     * AtomicLong getAndUpdate returns previous value and updates
63     * result of supplied function
64     */
65     public void testLongGetAndUpdate() {
66     AtomicLong a = new AtomicLong(1L);
67     assertEquals(1L, a.getAndUpdate(Atomic8Test::addLong17));
68     assertEquals(18L, a.getAndUpdate(Atomic8Test::addLong17));
69     assertEquals(35L, a.get());
70     }
71    
72     /**
73     * AtomicLong updateAndGet updates with supplied function and
74     * returns result.
75     */
76     public void testLongUpdateAndGet() {
77     AtomicLong a = new AtomicLong(1L);
78     assertEquals(18L, a.updateAndGet(Atomic8Test::addLong17));
79     assertEquals(35L, a.updateAndGet(Atomic8Test::addLong17));
80     }
81    
82     /**
83     * AtomicLong getAndAccumulate returns previous value and updates
84     * with supplied function.
85     */
86     public void testLongGetAndAccumulate() {
87     AtomicLong a = new AtomicLong(1L);
88     assertEquals(1L, a.getAndAccumulate(2L, Long::sum));
89     assertEquals(3L, a.getAndAccumulate(3L, Long::sum));
90     assertEquals(6L, a.get());
91     }
92    
93     /**
94     * AtomicLong accumulateAndGet updates with supplied function and
95     * returns result.
96     */
97     public void testLongAccumulateAndGet() {
98     AtomicLong a = new AtomicLong(1L);
99     assertEquals(7L, a.accumulateAndGet(6L, Long::sum));
100     assertEquals(10L, a.accumulateAndGet(3L, Long::sum));
101 jsr166 1.2 assertEquals(10L, a.get());
102 dl 1.1 }
103    
104     /**
105     * AtomicInteger getAndUpdate returns previous value and updates
106     * result of supplied function
107     */
108     public void testIntGetAndUpdate() {
109     AtomicInteger a = new AtomicInteger(1);
110     assertEquals(1, a.getAndUpdate(Atomic8Test::addInt17));
111     assertEquals(18, a.getAndUpdate(Atomic8Test::addInt17));
112     assertEquals(35, a.get());
113     }
114    
115     /**
116     * AtomicInteger updateAndGet updates with supplied function and
117     * returns result.
118     */
119     public void testIntUpdateAndGet() {
120     AtomicInteger a = new AtomicInteger(1);
121     assertEquals(18, a.updateAndGet(Atomic8Test::addInt17));
122     assertEquals(35, a.updateAndGet(Atomic8Test::addInt17));
123 jsr166 1.2 assertEquals(35, a.get());
124 dl 1.1 }
125    
126     /**
127     * AtomicInteger getAndAccumulate returns previous value and updates
128     * with supplied function.
129     */
130     public void testIntGetAndAccumulate() {
131     AtomicInteger a = new AtomicInteger(1);
132     assertEquals(1, a.getAndAccumulate(2, Integer::sum));
133     assertEquals(3, a.getAndAccumulate(3, Integer::sum));
134     assertEquals(6, a.get());
135     }
136    
137     /**
138     * AtomicInteger accumulateAndGet updates with supplied function and
139     * returns result.
140     */
141     public void testIntAccumulateAndGet() {
142     AtomicInteger a = new AtomicInteger(1);
143     assertEquals(7, a.accumulateAndGet(6, Integer::sum));
144     assertEquals(10, a.accumulateAndGet(3, Integer::sum));
145 jsr166 1.2 assertEquals(10, a.get());
146 dl 1.1 }
147    
148     /**
149     * AtomicReference getAndUpdate returns previous value and updates
150     * result of supplied function
151     */
152     public void testReferenceGetAndUpdate() {
153 jsr166 1.6 AtomicReference<Integer> a = new AtomicReference<>(one);
154 jsr166 1.7 assertEquals((Integer) 1, a.getAndUpdate(Atomic8Test::addInteger17));
155     assertEquals((Integer) 18, a.getAndUpdate(Atomic8Test::addInteger17));
156     assertEquals((Integer) 35, a.get());
157 dl 1.1 }
158    
159     /**
160     * AtomicReference updateAndGet updates with supplied function and
161     * returns result.
162     */
163     public void testReferenceUpdateAndGet() {
164 jsr166 1.6 AtomicReference<Integer> a = new AtomicReference<>(one);
165 jsr166 1.7 assertEquals((Integer) 18, a.updateAndGet(Atomic8Test::addInteger17));
166     assertEquals((Integer) 35, a.updateAndGet(Atomic8Test::addInteger17));
167     assertEquals((Integer) 35, a.get());
168 dl 1.1 }
169    
170     /**
171     * AtomicReference getAndAccumulate returns previous value and updates
172     * with supplied function.
173     */
174     public void testReferenceGetAndAccumulate() {
175 jsr166 1.6 AtomicReference<Integer> a = new AtomicReference<>(one);
176 jsr166 1.7 assertEquals((Integer) 1, a.getAndAccumulate(2, Atomic8Test::sumInteger));
177     assertEquals((Integer) 3, a.getAndAccumulate(3, Atomic8Test::sumInteger));
178     assertEquals((Integer) 6, a.get());
179 dl 1.1 }
180    
181     /**
182     * AtomicReference accumulateAndGet updates with supplied function and
183     * returns result.
184     */
185     public void testReferenceAccumulateAndGet() {
186 jsr166 1.6 AtomicReference<Integer> a = new AtomicReference<>(one);
187 jsr166 1.7 assertEquals((Integer) 7, a.accumulateAndGet(6, Atomic8Test::sumInteger));
188     assertEquals((Integer) 10, a.accumulateAndGet(3, Atomic8Test::sumInteger));
189     assertEquals((Integer) 10, a.get());
190 dl 1.1 }
191    
192     /**
193     * AtomicLongArray getAndUpdate returns previous value and updates
194     * result of supplied function
195     */
196     public void testLongArrayGetAndUpdate() {
197     AtomicLongArray a = new AtomicLongArray(1);
198     a.set(0, 1);
199     assertEquals(1L, a.getAndUpdate(0, Atomic8Test::addLong17));
200     assertEquals(18L, a.getAndUpdate(0, Atomic8Test::addLong17));
201     assertEquals(35L, a.get(0));
202     }
203    
204     /**
205     * AtomicLongArray updateAndGet updates with supplied function and
206     * returns result.
207     */
208     public void testLongArrayUpdateAndGet() {
209     AtomicLongArray a = new AtomicLongArray(1);
210     a.set(0, 1);
211     assertEquals(18L, a.updateAndGet(0, Atomic8Test::addLong17));
212     assertEquals(35L, a.updateAndGet(0, Atomic8Test::addLong17));
213 jsr166 1.2 assertEquals(35L, a.get(0));
214 dl 1.1 }
215    
216     /**
217     * AtomicLongArray getAndAccumulate returns previous value and updates
218     * with supplied function.
219     */
220     public void testLongArrayGetAndAccumulate() {
221     AtomicLongArray a = new AtomicLongArray(1);
222     a.set(0, 1);
223     assertEquals(1L, a.getAndAccumulate(0, 2L, Long::sum));
224     assertEquals(3L, a.getAndAccumulate(0, 3L, Long::sum));
225     assertEquals(6L, a.get(0));
226     }
227    
228     /**
229     * AtomicLongArray accumulateAndGet updates with supplied function and
230     * returns result.
231     */
232     public void testLongArrayAccumulateAndGet() {
233     AtomicLongArray a = new AtomicLongArray(1);
234     a.set(0, 1);
235     assertEquals(7L, a.accumulateAndGet(0, 6L, Long::sum));
236     assertEquals(10L, a.accumulateAndGet(0, 3L, Long::sum));
237 jsr166 1.2 assertEquals(10L, a.get(0));
238 dl 1.1 }
239    
240     /**
241     * AtomicIntegerArray getAndUpdate returns previous value and updates
242     * result of supplied function
243     */
244     public void testIntArrayGetAndUpdate() {
245     AtomicIntegerArray a = new AtomicIntegerArray(1);
246     a.set(0, 1);
247     assertEquals(1, a.getAndUpdate(0, Atomic8Test::addInt17));
248     assertEquals(18, a.getAndUpdate(0, Atomic8Test::addInt17));
249     assertEquals(35, a.get(0));
250     }
251    
252     /**
253     * AtomicIntegerArray updateAndGet updates with supplied function and
254     * returns result.
255     */
256     public void testIntArrayUpdateAndGet() {
257     AtomicIntegerArray a = new AtomicIntegerArray(1);
258     a.set(0, 1);
259     assertEquals(18, a.updateAndGet(0, Atomic8Test::addInt17));
260     assertEquals(35, a.updateAndGet(0, Atomic8Test::addInt17));
261 jsr166 1.2 assertEquals(35, a.get(0));
262 dl 1.1 }
263    
264     /**
265     * AtomicIntegerArray getAndAccumulate returns previous value and updates
266     * with supplied function.
267     */
268     public void testIntArrayGetAndAccumulate() {
269     AtomicIntegerArray a = new AtomicIntegerArray(1);
270     a.set(0, 1);
271     assertEquals(1, a.getAndAccumulate(0, 2, Integer::sum));
272     assertEquals(3, a.getAndAccumulate(0, 3, Integer::sum));
273     assertEquals(6, a.get(0));
274     }
275    
276     /**
277     * AtomicIntegerArray accumulateAndGet updates with supplied function and
278     * returns result.
279     */
280     public void testIntArrayAccumulateAndGet() {
281     AtomicIntegerArray a = new AtomicIntegerArray(1);
282     a.set(0, 1);
283     assertEquals(7, a.accumulateAndGet(0, 6, Integer::sum));
284     assertEquals(10, a.accumulateAndGet(0, 3, Integer::sum));
285     }
286    
287     /**
288     * AtomicReferenceArray getAndUpdate returns previous value and updates
289     * result of supplied function
290     */
291     public void testReferenceArrayGetAndUpdate() {
292     AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
293     a.set(0, one);
294 jsr166 1.7 assertEquals((Integer) 1, a.getAndUpdate(0, Atomic8Test::addInteger17));
295     assertEquals((Integer) 18, a.getAndUpdate(0, Atomic8Test::addInteger17));
296     assertEquals((Integer) 35, a.get(0));
297 dl 1.1 }
298    
299     /**
300     * AtomicReferenceArray updateAndGet updates with supplied function and
301     * returns result.
302     */
303     public void testReferenceArrayUpdateAndGet() {
304     AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
305     a.set(0, one);
306 jsr166 1.7 assertEquals((Integer) 18, a.updateAndGet(0, Atomic8Test::addInteger17));
307     assertEquals((Integer) 35, a.updateAndGet(0, Atomic8Test::addInteger17));
308 dl 1.1 }
309    
310     /**
311     * AtomicReferenceArray getAndAccumulate returns previous value and updates
312     * with supplied function.
313     */
314     public void testReferenceArrayGetAndAccumulate() {
315     AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
316     a.set(0, one);
317 jsr166 1.7 assertEquals((Integer) 1, a.getAndAccumulate(0, 2, Atomic8Test::sumInteger));
318     assertEquals((Integer) 3, a.getAndAccumulate(0, 3, Atomic8Test::sumInteger));
319     assertEquals((Integer) 6, a.get(0));
320 dl 1.1 }
321    
322     /**
323     * AtomicReferenceArray accumulateAndGet updates with supplied function and
324     * returns result.
325     */
326     public void testReferenceArrayAccumulateAndGet() {
327     AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
328     a.set(0, one);
329 jsr166 1.7 assertEquals((Integer) 7, a.accumulateAndGet(0, 6, Atomic8Test::sumInteger));
330     assertEquals((Integer) 10, a.accumulateAndGet(0, 3, Atomic8Test::sumInteger));
331 dl 1.1 }
332    
333     /**
334     * AtomicLongFieldUpdater getAndUpdate returns previous value and updates
335     * result of supplied function
336     */
337     public void testLongFieldUpdaterGetAndUpdate() {
338 jsr166 1.2 AtomicLongFieldUpdater a = aLongFieldUpdater();
339 dl 1.1 a.set(this, 1);
340     assertEquals(1L, a.getAndUpdate(this, Atomic8Test::addLong17));
341     assertEquals(18L, a.getAndUpdate(this, Atomic8Test::addLong17));
342     assertEquals(35L, a.get(this));
343 jsr166 1.2 assertEquals(35L, aLongField);
344 dl 1.1 }
345    
346     /**
347     * AtomicLongFieldUpdater updateAndGet updates with supplied function and
348     * returns result.
349     */
350     public void testLongFieldUpdaterUpdateAndGet() {
351 jsr166 1.2 AtomicLongFieldUpdater a = aLongFieldUpdater();
352 dl 1.1 a.set(this, 1);
353     assertEquals(18L, a.updateAndGet(this, Atomic8Test::addLong17));
354     assertEquals(35L, a.updateAndGet(this, Atomic8Test::addLong17));
355 jsr166 1.2 assertEquals(35L, a.get(this));
356     assertEquals(35L, aLongField);
357 dl 1.1 }
358    
359     /**
360     * AtomicLongFieldUpdater getAndAccumulate returns previous value
361     * and updates with supplied function.
362     */
363     public void testLongFieldUpdaterGetAndAccumulate() {
364 jsr166 1.2 AtomicLongFieldUpdater a = aLongFieldUpdater();
365 dl 1.1 a.set(this, 1);
366     assertEquals(1L, a.getAndAccumulate(this, 2L, Long::sum));
367     assertEquals(3L, a.getAndAccumulate(this, 3L, Long::sum));
368     assertEquals(6L, a.get(this));
369 jsr166 1.2 assertEquals(6L, aLongField);
370 dl 1.1 }
371    
372     /**
373     * AtomicLongFieldUpdater accumulateAndGet updates with supplied
374     * function and returns result.
375     */
376     public void testLongFieldUpdaterAccumulateAndGet() {
377 jsr166 1.2 AtomicLongFieldUpdater a = aLongFieldUpdater();
378 dl 1.1 a.set(this, 1);
379     assertEquals(7L, a.accumulateAndGet(this, 6L, Long::sum));
380     assertEquals(10L, a.accumulateAndGet(this, 3L, Long::sum));
381 jsr166 1.2 assertEquals(10L, a.get(this));
382     assertEquals(10L, aLongField);
383 dl 1.1 }
384    
385     /**
386     * AtomicIntegerFieldUpdater getAndUpdate returns previous value and updates
387     * result of supplied function
388     */
389     public void testIntegerFieldUpdaterGetAndUpdate() {
390 jsr166 1.2 AtomicIntegerFieldUpdater a = anIntFieldUpdater();
391 dl 1.1 a.set(this, 1);
392     assertEquals(1, a.getAndUpdate(this, Atomic8Test::addInt17));
393     assertEquals(18, a.getAndUpdate(this, Atomic8Test::addInt17));
394     assertEquals(35, a.get(this));
395 jsr166 1.2 assertEquals(35, anIntField);
396 dl 1.1 }
397    
398     /**
399     * AtomicIntegerFieldUpdater updateAndGet updates with supplied function and
400     * returns result.
401     */
402     public void testIntegerFieldUpdaterUpdateAndGet() {
403 jsr166 1.2 AtomicIntegerFieldUpdater a = anIntFieldUpdater();
404 dl 1.1 a.set(this, 1);
405     assertEquals(18, a.updateAndGet(this, Atomic8Test::addInt17));
406     assertEquals(35, a.updateAndGet(this, Atomic8Test::addInt17));
407 jsr166 1.2 assertEquals(35, a.get(this));
408     assertEquals(35, anIntField);
409 dl 1.1 }
410    
411     /**
412     * AtomicIntegerFieldUpdater getAndAccumulate returns previous value
413     * and updates with supplied function.
414     */
415     public void testIntegerFieldUpdaterGetAndAccumulate() {
416 jsr166 1.2 AtomicIntegerFieldUpdater a = anIntFieldUpdater();
417 dl 1.1 a.set(this, 1);
418     assertEquals(1, a.getAndAccumulate(this, 2, Integer::sum));
419     assertEquals(3, a.getAndAccumulate(this, 3, Integer::sum));
420     assertEquals(6, a.get(this));
421 jsr166 1.2 assertEquals(6, anIntField);
422 dl 1.1 }
423    
424     /**
425     * AtomicIntegerFieldUpdater accumulateAndGet updates with supplied
426     * function and returns result.
427     */
428     public void testIntegerFieldUpdaterAccumulateAndGet() {
429 jsr166 1.2 AtomicIntegerFieldUpdater a = anIntFieldUpdater();
430 dl 1.1 a.set(this, 1);
431     assertEquals(7, a.accumulateAndGet(this, 6, Integer::sum));
432     assertEquals(10, a.accumulateAndGet(this, 3, Integer::sum));
433 jsr166 1.2 assertEquals(10, a.get(this));
434     assertEquals(10, anIntField);
435 dl 1.1 }
436    
437     /**
438     * AtomicReferenceFieldUpdater getAndUpdate returns previous value
439     * and updates result of supplied function
440     */
441     public void testReferenceFieldUpdaterGetAndUpdate() {
442 jsr166 1.2 AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
443 dl 1.1 a.set(this, one);
444 jsr166 1.7 assertEquals((Integer) 1, a.getAndUpdate(this, Atomic8Test::addInteger17));
445     assertEquals((Integer) 18, a.getAndUpdate(this, Atomic8Test::addInteger17));
446     assertEquals((Integer) 35, a.get(this));
447     assertEquals((Integer) 35, anIntegerField);
448 dl 1.1 }
449    
450     /**
451     * AtomicReferenceFieldUpdater updateAndGet updates with supplied
452     * function and returns result.
453     */
454     public void testReferenceFieldUpdaterUpdateAndGet() {
455 jsr166 1.2 AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
456 dl 1.1 a.set(this, one);
457 jsr166 1.7 assertEquals((Integer) 18, a.updateAndGet(this, Atomic8Test::addInteger17));
458     assertEquals((Integer) 35, a.updateAndGet(this, Atomic8Test::addInteger17));
459     assertEquals((Integer) 35, a.get(this));
460     assertEquals((Integer) 35, anIntegerField);
461 dl 1.1 }
462    
463     /**
464     * AtomicReferenceFieldUpdater returns previous value and updates
465     * with supplied function.
466     */
467     public void testReferenceFieldUpdaterGetAndAccumulate() {
468 jsr166 1.2 AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
469 dl 1.1 a.set(this, one);
470 jsr166 1.7 assertEquals((Integer) 1, a.getAndAccumulate(this, 2, Atomic8Test::sumInteger));
471     assertEquals((Integer) 3, a.getAndAccumulate(this, 3, Atomic8Test::sumInteger));
472     assertEquals((Integer) 6, a.get(this));
473     assertEquals((Integer) 6, anIntegerField);
474 dl 1.1 }
475    
476     /**
477     * AtomicReferenceFieldUpdater accumulateAndGet updates with
478     * supplied function and returns result.
479     */
480     public void testReferenceFieldUpdaterAccumulateAndGet() {
481 jsr166 1.2 AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
482 dl 1.1 a.set(this, one);
483 jsr166 1.7 assertEquals((Integer) 7, a.accumulateAndGet(this, 6, Atomic8Test::sumInteger));
484     assertEquals((Integer) 10, a.accumulateAndGet(this, 3, Atomic8Test::sumInteger));
485     assertEquals((Integer) 10, a.get(this));
486     assertEquals((Integer) 10, anIntegerField);
487 dl 1.1 }
488    
489     /**
490 jsr166 1.2 * All Atomic getAndUpdate methods throw NullPointerException on
491     * null function argument
492 dl 1.1 */
493     public void testGetAndUpdateNPE() {
494 jsr166 1.2 Runnable[] throwingActions = {
495     () -> new AtomicLong().getAndUpdate(null),
496     () -> new AtomicInteger().getAndUpdate(null),
497     () -> new AtomicReference().getAndUpdate(null),
498     () -> new AtomicLongArray(1).getAndUpdate(0, null),
499     () -> new AtomicIntegerArray(1).getAndUpdate(0, null),
500     () -> new AtomicReferenceArray(1).getAndUpdate(0, null),
501     () -> aLongFieldUpdater().getAndUpdate(this, null),
502     () -> anIntFieldUpdater().getAndUpdate(this, null),
503     () -> anIntegerFieldUpdater().getAndUpdate(this, null),
504     ////() -> aLongFieldUpdater().getAndUpdate(null, Atomic8Test::addLong17),
505     ////() -> anIntFieldUpdater().getAndUpdate(null, Atomic8Test::addInt17),
506     ////() -> anIntegerFieldUpdater().getAndUpdate(null, Atomic8Test::addInteger17),
507     };
508     assertThrows(NullPointerException.class, throwingActions);
509 dl 1.1 }
510    
511     /**
512 jsr166 1.2 * All Atomic updateAndGet methods throw NullPointerException on null function argument
513     */
514     public void testUpdateAndGetNPE() {
515     Runnable[] throwingActions = {
516     () -> new AtomicLong().updateAndGet(null),
517     () -> new AtomicInteger().updateAndGet(null),
518     () -> new AtomicReference().updateAndGet(null),
519     () -> new AtomicLongArray(1).updateAndGet(0, null),
520     () -> new AtomicIntegerArray(1).updateAndGet(0, null),
521     () -> new AtomicReferenceArray(1).updateAndGet(0, null),
522     () -> aLongFieldUpdater().updateAndGet(this, null),
523     () -> anIntFieldUpdater().updateAndGet(this, null),
524     () -> anIntegerFieldUpdater().updateAndGet(this, null),
525     };
526     assertThrows(NullPointerException.class, throwingActions);
527     }
528    
529     /**
530     * All Atomic getAndAccumulate methods throw NullPointerException
531     * on null function argument
532 dl 1.1 */
533     public void testGetAndAccumulateNPE() {
534 jsr166 1.2 Runnable[] throwingActions = {
535     () -> new AtomicLong().getAndAccumulate(1L, null),
536     () -> new AtomicInteger().getAndAccumulate(1, null),
537     () -> new AtomicReference().getAndAccumulate(one, null),
538     () -> new AtomicLongArray(1).getAndAccumulate(0, 1L, null),
539     () -> new AtomicIntegerArray(1).getAndAccumulate(0, 1, null),
540     () -> new AtomicReferenceArray(1).getAndAccumulate(0, one, null),
541     () -> aLongFieldUpdater().getAndAccumulate(this, 1L, null),
542     () -> anIntFieldUpdater().getAndAccumulate(this, 1, null),
543     () -> anIntegerFieldUpdater().getAndAccumulate(this, one, null),
544     };
545     assertThrows(NullPointerException.class, throwingActions);
546 dl 1.1 }
547    
548     /**
549 jsr166 1.2 * All Atomic accumulateAndGet methods throw NullPointerException
550     * on null function argument
551 dl 1.1 */
552     public void testAccumulateAndGetNPE() {
553 jsr166 1.2 Runnable[] throwingActions = {
554     () -> new AtomicLong().accumulateAndGet(1L, null),
555     () -> new AtomicInteger().accumulateAndGet(1, null),
556     () -> new AtomicReference().accumulateAndGet(one, null),
557     () -> new AtomicLongArray(1).accumulateAndGet(0, 1L, null),
558     () -> new AtomicIntegerArray(1).accumulateAndGet(0, 1, null),
559     () -> new AtomicReferenceArray(1).accumulateAndGet(0, one, null),
560     () -> aLongFieldUpdater().accumulateAndGet(this, 1L, null),
561     () -> anIntFieldUpdater().accumulateAndGet(this, 1, null),
562     () -> anIntegerFieldUpdater().accumulateAndGet(this, one, null),
563     };
564     assertThrows(NullPointerException.class, throwingActions);
565 dl 1.1 }
566    
567     }