From: Robert Varga Date: Fri, 2 Oct 2020 13:28:32 +0000 (+0200) Subject: Convert uint tests to assertThrows() X-Git-Tag: v6.0.0~39 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=b42a6170ca5ae9f8d054921b570e967512128937;p=yangtools.git Convert uint tests to assertThrows() We have a number of tests which can be consolidated, use assertThrows. This flushes out a bad test case, which is corrected. Change-Id: I3b0b760cb89a4dbd93ebe44af2ed917b0698fc31 Signed-off-by: Robert Varga (cherry picked from commit b355455a078fbe3043c34bbe4f1ceab39aef11a6) --- diff --git a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java index 7a5c34e5fd..17f7ec2976 100644 --- a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java +++ b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java @@ -123,32 +123,16 @@ public class Uint16Test { } @Test - public void testNegativeByte() { + public void testNegativeValues() { assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf((byte)-1)); - } - - @Test - public void testNegativeShort() { assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf((short)-1)); - } - - @Test - public void testNegativeInt() { assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(-1)); - } - - @Test - public void testNegativeLong() { assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(-1L)); } @Test - public void testBigInt() { + public void testLargeValues() { assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(65536)); - } - - @Test - public void testBigLong() { assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(65536L)); } diff --git a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java index 2860e5badf..b1a122647a 100644 --- a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java +++ b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java @@ -129,27 +129,15 @@ public class Uint32Test { } @Test - public void testNegativeByte() { + public void testNegativeValues() { assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf((byte)-1)); - } - - @Test - public void testNegativeShort() { assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf((short)-1)); - } - - @Test - public void testNegativeInt() { assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf(-1)); - } - - @Test - public void testNegativeLong() { assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf(-1L)); } @Test - public void testBigLong() { + public void testLargeValues() { assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf(4294967296L)); } diff --git a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java index 12f096379f..521eb33690 100644 --- a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java +++ b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java @@ -138,42 +138,23 @@ public class Uint64Test { } @Test - public void testNegativeByte() { + public void testNegativeValues() { assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf((byte)-1)); - } - - @Test - public void testNegativeShort() { assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf((short)-1)); - } - - @Test - public void testNegativeInt() { assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(-1)); - } - - @Test - public void testNegativeLong() { assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(-1L)); - } - - @Test - public void testNegativeBigInteger() { assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(new BigInteger("-1"))); } @Test - public void testBigBigInteger() { - assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(new BigInteger("0x10000000000000000"))); + public void testLargeValues() { + final BigInteger big = new BigInteger("10000000000000000", 16); + assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(big)); } @Test - public void testNullValueOfString() { + public void testNullValueOf() { assertThrows(NullPointerException.class, () -> Uint64.valueOf((String) null)); - } - - @Test - public void testNullValueOfBigInteger() { assertThrows(NullPointerException.class, () -> Uint64.valueOf((BigInteger) null)); } } diff --git a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java index 4f6cd6ef55..83c516ceea 100644 --- a/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java +++ b/yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java @@ -114,37 +114,17 @@ public class Uint8Test { } @Test - public void testNegativeByte() { + public void testNegativeValues() { assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf((byte)-1)); - } - - @Test - public void testNegativeShort() { assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf((short)-1)); - } - - @Test - public void testNegativeInt() { assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(-1)); - } - - @Test - public void testNegativeLong() { assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(-1L)); } @Test - public void testBigShort() { + public void testLargeValues() { assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf((short)256)); - } - - @Test - public void testBigInt() { assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(256)); - } - - @Test - public void testBigLong() { assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(256L)); }