491 |
|
* null function argument |
492 |
|
*/ |
493 |
|
public void testGetAndUpdateNPE() { |
494 |
< |
Runnable[] throwingActions = { |
494 |
> |
assertThrows( |
495 |
> |
NullPointerException.class, |
496 |
|
() -> new AtomicLong().getAndUpdate(null), |
497 |
|
() -> new AtomicInteger().getAndUpdate(null), |
498 |
|
() -> new AtomicReference().getAndUpdate(null), |
501 |
|
() -> new AtomicReferenceArray(1).getAndUpdate(0, null), |
502 |
|
() -> aLongFieldUpdater().getAndUpdate(this, null), |
503 |
|
() -> anIntFieldUpdater().getAndUpdate(this, null), |
504 |
< |
() -> anIntegerFieldUpdater().getAndUpdate(this, null), |
504 |
< |
}; |
505 |
< |
assertThrows(NullPointerException.class, throwingActions); |
504 |
> |
() -> anIntegerFieldUpdater().getAndUpdate(this, null)); |
505 |
|
} |
506 |
|
|
507 |
|
/** |
508 |
|
* All Atomic updateAndGet methods throw NullPointerException on null function argument |
509 |
|
*/ |
510 |
|
public void testUpdateAndGetNPE() { |
511 |
< |
Runnable[] throwingActions = { |
511 |
> |
assertThrows( |
512 |
> |
NullPointerException.class, |
513 |
|
() -> new AtomicLong().updateAndGet(null), |
514 |
|
() -> new AtomicInteger().updateAndGet(null), |
515 |
|
() -> new AtomicReference().updateAndGet(null), |
518 |
|
() -> new AtomicReferenceArray(1).updateAndGet(0, null), |
519 |
|
() -> aLongFieldUpdater().updateAndGet(this, null), |
520 |
|
() -> anIntFieldUpdater().updateAndGet(this, null), |
521 |
< |
() -> anIntegerFieldUpdater().updateAndGet(this, null), |
522 |
< |
}; |
523 |
< |
assertThrows(NullPointerException.class, throwingActions); |
521 |
> |
() -> anIntegerFieldUpdater().updateAndGet(this, null)); |
522 |
|
} |
523 |
|
|
524 |
|
/** |
526 |
|
* on null function argument |
527 |
|
*/ |
528 |
|
public void testGetAndAccumulateNPE() { |
529 |
< |
Runnable[] throwingActions = { |
529 |
> |
assertThrows( |
530 |
> |
NullPointerException.class, |
531 |
|
() -> new AtomicLong().getAndAccumulate(1L, null), |
532 |
|
() -> new AtomicInteger().getAndAccumulate(1, null), |
533 |
|
() -> new AtomicReference().getAndAccumulate(one, null), |
536 |
|
() -> new AtomicReferenceArray(1).getAndAccumulate(0, one, null), |
537 |
|
() -> aLongFieldUpdater().getAndAccumulate(this, 1L, null), |
538 |
|
() -> anIntFieldUpdater().getAndAccumulate(this, 1, null), |
539 |
< |
() -> anIntegerFieldUpdater().getAndAccumulate(this, one, null), |
541 |
< |
}; |
542 |
< |
assertThrows(NullPointerException.class, throwingActions); |
539 |
> |
() -> anIntegerFieldUpdater().getAndAccumulate(this, one, null)); |
540 |
|
} |
541 |
|
|
542 |
|
/** |
544 |
|
* on null function argument |
545 |
|
*/ |
546 |
|
public void testAccumulateAndGetNPE() { |
547 |
< |
Runnable[] throwingActions = { |
547 |
> |
assertThrows( |
548 |
> |
NullPointerException.class, |
549 |
|
() -> new AtomicLong().accumulateAndGet(1L, null), |
550 |
|
() -> new AtomicInteger().accumulateAndGet(1, null), |
551 |
|
() -> new AtomicReference().accumulateAndGet(one, null), |
554 |
|
() -> new AtomicReferenceArray(1).accumulateAndGet(0, one, null), |
555 |
|
() -> aLongFieldUpdater().accumulateAndGet(this, 1L, null), |
556 |
|
() -> anIntFieldUpdater().accumulateAndGet(this, 1, null), |
557 |
< |
() -> anIntegerFieldUpdater().accumulateAndGet(this, one, null), |
560 |
< |
}; |
561 |
< |
assertThrows(NullPointerException.class, throwingActions); |
557 |
> |
() -> anIntegerFieldUpdater().accumulateAndGet(this, one, null)); |
558 |
|
} |
559 |
|
|
560 |
|
/** |
567 |
|
final AtomicLongFieldUpdater longUpdater = aLongFieldUpdater(); |
568 |
|
final AtomicIntegerFieldUpdater intUpdater = anIntFieldUpdater(); |
569 |
|
final AtomicReferenceFieldUpdater refUpdater = anIntegerFieldUpdater(); |
574 |
– |
final Object obj = new Object(); |
570 |
|
for (Object x : new Object[]{ new Object(), null }) { |
571 |
< |
Runnable[] throwingActions = { |
571 |
> |
assertThrows( |
572 |
> |
ClassCastException.class, |
573 |
|
() -> longUpdater.get(x), |
574 |
|
() -> intUpdater.get(x), |
575 |
|
() -> refUpdater.get(x), |
587 |
|
|
588 |
|
() -> longUpdater.compareAndSet(x, 17L, 42L), |
589 |
|
() -> intUpdater.compareAndSet(x, 17, 42), |
590 |
< |
() -> refUpdater.compareAndSet(x, (Integer) 17, (Integer) 42), |
595 |
< |
}; |
596 |
< |
assertThrows(ClassCastException.class, throwingActions); |
590 |
> |
() -> refUpdater.compareAndSet(x, (Integer) 17, (Integer) 42)); |
591 |
|
} |
592 |
|
} |
593 |
|
|