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>
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 java.io.ByteArrayInputStream;
assertEquals(Uint64.valueOf(65535), Uint16.MAX_VALUE.toUint64());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testToUint8() {
- Uint16.MAX_VALUE.toUint8();
+ assertThrows(IllegalArgumentException.class, () -> Uint16.MAX_VALUE.toUint8());
}
@Test
assertSame(source, read);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeByte() {
- Uint16.valueOf((byte)-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeShort() {
- Uint16.valueOf((short)-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeInt() {
- Uint16.valueOf(-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeLong() {
- Uint16.valueOf(-1L);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBigInt() {
- Uint16.valueOf(65536);
+ @Test
+ public void testNegativeValues() {
+ assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf((byte)-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf((short)-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(-1L));
}
- @Test(expected = IllegalArgumentException.class)
- public void testBigLong() {
- Uint16.valueOf(65536L);
+ @Test
+ public void testLargeValues() {
+ assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(65536));
+ assertThrows(IllegalArgumentException.class, () -> Uint16.valueOf(65536L));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testNullValueOfString() {
- Uint16.valueOf((String) null);
+ assertThrows(NullPointerException.class, () -> Uint16.valueOf((String) null));
}
}
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;
assertEquals(Uint64.valueOf(4294967295L), Uint32.MAX_VALUE.toUint64());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testToUint8() {
- Uint32.MAX_VALUE.toUint8();
+ assertThrows(IllegalArgumentException.class, () -> Uint32.MAX_VALUE.toUint8());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testToUint16() {
- Uint32.MAX_VALUE.toUint16();
+ 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));
}
}
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.UnsignedLong;
assertEquals(Uint32.TEN, Uint64.TEN.toUint32());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testToUint8() {
- Uint64.MAX_VALUE.toUint8();
+ assertThrows(IllegalArgumentException.class, () -> Uint64.MAX_VALUE.toUint8());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testToUint16() {
- Uint64.MAX_VALUE.toUint16();
+ assertThrows(IllegalArgumentException.class, () -> Uint64.MAX_VALUE.toUint16());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testToUint32() {
- Uint64.MAX_VALUE.toUint32();
+ assertThrows(IllegalArgumentException.class, () -> Uint64.MAX_VALUE.toUint32());
}
@Test
assertSame(source, read);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeByte() {
- Uint64.valueOf((byte)-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeShort() {
- Uint64.valueOf((short)-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeInt() {
- Uint64.valueOf(-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeLong() {
- Uint64.valueOf(-1L);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeBigInteger() {
- Uint64.valueOf(new BigInteger("-1"));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBigBigInteger() {
- Uint64.valueOf(new BigInteger("0x10000000000000000"));
+ @Test
+ public void testNegativeValues() {
+ assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf((byte)-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf((short)-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(-1L));
+ assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(new BigInteger("-1")));
}
- @Test(expected = NullPointerException.class)
- public void testNullValueOfString() {
- Uint64.valueOf((String) null);
+ @Test
+ public void testLargeValues() {
+ final BigInteger big = new BigInteger("10000000000000000", 16);
+ assertThrows(IllegalArgumentException.class, () -> Uint64.valueOf(big));
}
- @Test(expected = NullPointerException.class)
- public void testNullValueOfBigInteger() {
- Uint64.valueOf((BigInteger) null);
+ @Test
+ public void testNullValueOf() {
+ assertThrows(NullPointerException.class, () -> Uint64.valueOf((String) null));
+ assertThrows(NullPointerException.class, () -> Uint64.valueOf((BigInteger) null));
}
}
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 java.io.ByteArrayInputStream;
assertSame(source, read);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeByte() {
- Uint8.valueOf((byte)-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeShort() {
- Uint8.valueOf((short)-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeInt() {
- Uint8.valueOf(-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeLong() {
- Uint8.valueOf(-1L);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBigShort() {
- Uint8.valueOf((short)256);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBigInt() {
- Uint8.valueOf(256);
+ @Test
+ public void testNegativeValues() {
+ assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf((byte)-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf((short)-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(-1));
+ assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(-1L));
}
- @Test(expected = IllegalArgumentException.class)
- public void testBigLong() {
- Uint8.valueOf(256L);
+ @Test
+ public void testLargeValues() {
+ assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf((short)256));
+ assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(256));
+ assertThrows(IllegalArgumentException.class, () -> Uint8.valueOf(256L));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testNullValueOfString() {
- Uint8.valueOf((String) null);
+ assertThrows(NullPointerException.class, () -> Uint8.valueOf((String) null));
}
}