diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java index 8f44575bda..74cbd07271 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java @@ -72,10 +72,7 @@ public void testMapEntrySetIteratorEntrySetValueCrossCheck() { TestBidiMapEntrySet.this.verify(); if (!isSetValueSupported()) { - try { - entry1.setValue(newValue1); - } catch (final UnsupportedOperationException ex) { - } + assertThrows(UnsupportedOperationException.class, () -> entry1.setValue(newValue1)); return; } diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapDecoratorTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapDecoratorTest.java index 4f10c4324c..2d6483d6b0 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapDecoratorTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapDecoratorTest.java @@ -27,7 +27,7 @@ * @param the type of the keys in this map * @param the type of the values in this map */ -public class AbstractOrderedBidiMapDecoratorTest +public abstract class AbstractOrderedBidiMapDecoratorTest extends AbstractOrderedBidiMapTest { /** diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java index 397cb03d01..db67c94ecd 100644 --- a/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java @@ -56,12 +56,8 @@ public void testAddNodeAfter() { resetEmpty(); final AbstractLinkedList list = getCollection(); if (!isAddSupported()) { - try { - list.addFirst(null); - } catch (final UnsupportedOperationException ex) { - } + assertThrows(UnsupportedOperationException.class, () -> list.addFirst(null)); } - list.addFirst((E) "value1"); list.addNodeAfter(list.getNode(0, false), (E) "value2"); assertEquals("value1", list.getFirst()); @@ -110,10 +106,7 @@ public void testRemoveFirst() { resetEmpty(); final AbstractLinkedList list = getCollection(); if (!isRemoveSupported()) { - try { - list.removeFirst(); - } catch (final UnsupportedOperationException ex) { - } + assertThrows(UnsupportedOperationException.class, list::removeFirst); } list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); @@ -136,10 +129,7 @@ public void testRemoveLast() { resetEmpty(); final AbstractLinkedList list = getCollection(); if (!isRemoveSupported()) { - try { - list.removeLast(); - } catch (final UnsupportedOperationException ex) { - } + assertThrows(UnsupportedOperationException.class, list::removeLast); } list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java index 6bd5589233..a5be4c23f5 100644 --- a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java @@ -819,15 +819,9 @@ public void testListListIterator() { @Test public void testListListIteratorByIndex() { resetFull(); - try { - getCollection().listIterator(-1); - } catch (final IndexOutOfBoundsException ex) { - } + assertThrows(IndexOutOfBoundsException.class, () -> getCollection().listIterator(-1)); resetFull(); - try { - getCollection().listIterator(getCollection().size() + 1); - } catch (final IndexOutOfBoundsException ex) { - } + assertThrows(IndexOutOfBoundsException.class, () -> getCollection().listIterator(getCollection().size() + 1)); resetFull(); for (int i = 0; i <= getConfirmed().size(); i++) { forwardTest(getCollection().listIterator(i), i); diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java index b3faa0133c..91a6737efb 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java @@ -280,10 +280,7 @@ public void testMapEntrySetIteratorEntrySetValue() { verify(); if (!isSetValueSupported()) { - try { - entry1.setValue(newValue1); - } catch (final UnsupportedOperationException ex) { - } + assertThrows(UnsupportedOperationException.class, () -> entry1.setValue(newValue1)); return; }