Convert uint tests to assertThrows()
[yangtools.git] / yang / yang-common / src / test / java / org / opendaylight / yangtools / yang / common / Uint32Test.java
index 81716a14e28f5608923cd4c5f2808cf0369b2736..b1a122647a1f007c9ca31e23749614842a0817d0 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.common;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.primitives.UnsignedInteger;
@@ -95,6 +96,20 @@ public class Uint32Test {
 
         assertSame(Uint32.valueOf(5), Uint32.valueOf(UnsignedInteger.fromIntBits(5)));
         assertEquals(UnsignedInteger.fromIntBits(5), Uint32.valueOf(5).toGuava());
+
+        assertEquals(Uint8.TEN, Uint32.TEN.toUint8());
+        assertEquals(Uint16.TEN, Uint32.TEN.toUint16());
+        assertEquals(Uint64.valueOf(4294967295L), Uint32.MAX_VALUE.toUint64());
+    }
+
+    @Test
+    public void testToUint8() {
+        assertThrows(IllegalArgumentException.class, () -> Uint32.MAX_VALUE.toUint8());
+    }
+
+    @Test
+    public void testToUint16() {
+        assertThrows(IllegalArgumentException.class, () -> Uint32.MAX_VALUE.toUint16());
     }
 
     @Test
@@ -113,33 +128,21 @@ public class Uint32Test {
         assertSame(source, read);
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testNegativeByte() {
-        Uint32.valueOf((byte)-1);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testNegativeShort() {
-        Uint32.valueOf((short)-1);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testNegativeInt() {
-        Uint32.valueOf(-1);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testNegativeLong() {
-        Uint32.valueOf(-1L);
+    @Test
+    public void testNegativeValues() {
+        assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf((byte)-1));
+        assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf((short)-1));
+        assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf(-1));
+        assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf(-1L));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testBigLong() {
-        Uint32.valueOf(4294967296L);
+    @Test
+    public void testLargeValues() {
+        assertThrows(IllegalArgumentException.class, () -> Uint32.valueOf(4294967296L));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testNullValueOfString() {
-        Uint32.valueOf((String) null);
+        assertThrows(NullPointerException.class, () -> Uint32.valueOf((String) null));
     }
 }