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;
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
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));
}
}