From 033943bb481f354f50ec30fa01930a26e21393a3 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 22 Feb 2020 11:11:28 +0100 Subject: [PATCH] Convert ConstantArrayCollectionTest to use assertThrows() This reduces verbosity of the test. Change-Id: I31a3dc7850c5286faba5335cff04ec67ee646cbd Signed-off-by: Robert Varga --- .../util/ConstantArrayCollectionTest.java | 49 +++---------------- 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java index c33c9cb705..bc0c2deaf6 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java @@ -9,8 +9,8 @@ package org.opendaylight.yangtools.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -63,46 +63,11 @@ public class ConstantArrayCollectionTest { public void testProtection() { final Collection c = create(); - try { - c.add(null); - fail(); - } catch (UnsupportedOperationException e) { - // OK - } - - try { - c.remove(null); - fail(); - } catch (UnsupportedOperationException e) { - // OK - } - - try { - c.addAll(null); - fail(); - } catch (UnsupportedOperationException e) { - // OK - } - - try { - c.removeAll(null); - fail(); - } catch (UnsupportedOperationException e) { - // OK - } - - try { - c.retainAll(null); - fail(); - } catch (UnsupportedOperationException e) { - // OK - } - - try { - c.clear(); - fail(); - } catch (UnsupportedOperationException e) { - // OK - } + assertThrows(UnsupportedOperationException.class, () -> c.add(null)); + assertThrows(UnsupportedOperationException.class, () -> c.remove(null)); + assertThrows(UnsupportedOperationException.class, () -> c.addAll(null)); + assertThrows(UnsupportedOperationException.class, () -> c.removeAll(null)); + assertThrows(UnsupportedOperationException.class, () -> c.retainAll(null)); + assertThrows(UnsupportedOperationException.class, () -> c.clear()); } } -- 2.36.6