Convert uint tests to assertThrows() 56/92856/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 2 Oct 2020 13:28:32 +0000 (15:28 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 2 Oct 2020 14:09:36 +0000 (16:09 +0200)
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 <robert.varga@pantheon.tech>
(cherry picked from commit b355455a078fbe3043c34bbe4f1ceab39aef11a6)

yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java
yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java
yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java
yang/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java

index 7a5c34e5fd739c0dc55b9d452db910e5373857b1..17f7ec2976feeecdfb1982123881486ebeeda349 100644 (file)
@@ -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));
     }
 
index 2860e5badf638df29f2ceb6d90bdab352621910a..b1a122647a1f007c9ca31e23749614842a0817d0 100644 (file)
@@ -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));
     }
 
index 12f096379f93678232eafe901a3fa2bd9b7b0275..521eb33690df0a449a620af4b7a279900081b836 100644 (file)
@@ -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));
     }
 }
index 4f6cd6ef5546e3e855f389cd2bbb373f1913710b..83c516ceeabb72220201a57d043b05fd7b55ea01 100644 (file)
@@ -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));
     }