@Test public void testParseHexPrefixEquals() throws Exception { long i = 123456; String s = Long.toHexString(i); String s1 = "0x" + s; String s2 = "0X" + s; // Transitive property means we only have to test twice assertEquals(ParseLong.parseHex(s), ParseLong.parseHex(s1)); assertEquals(ParseLong.parseHex(s1), ParseLong.parseHex(s2)); }
// Test prefix with no value reject @Test(expected = NumberFormatException.class) public void testParseHex_PrefixNoValue() throws Exception { String s = "0x"; ParseLong.parseHex(s); }
// Test positive sign prefix reject (no prefix) @Test(expected = NumberFormatException.class) public void testParseHex_Positive3() throws Exception { String s = "+12AB"; ParseLong.parseHex(s); }
// Test null @Test(expected = NumberFormatException.class) public void testParseHex_Null() throws Exception { ParseLong.parseHex(null); }
// Test bad @Test(expected = NumberFormatException.class) public void testParseHex_Bad() throws Exception { ParseLong.parseHex("12AB-**&1'"); }
// Test negative sign prefix reject (after prefix) @Test(expected = NumberFormatException.class) public void testParseHex_Negative2() throws Exception { String s = "0x-12AC"; ParseLong.parseHex(s); }
// Technically this is the same as MaxUnsigned @Test public void testParseHexMinSigned() throws Exception { long i = Long.MIN_VALUE; String s = "0x" + Long.toHexString(i); assertEquals(i, ParseLong.parseHex(s)); }
// For values larger than the unsigned max, the method shouldn't thrown an exception but it will // return a // garbage result @Test public void testParseHexMaxUnsignedOverflow() throws Exception { String s = "0x10000000000000000"; ParseLong.parseHex(s); }
@Test public void testParseHexMaxUnsigned() throws Exception { long i = 0xFFFFFFFFFFFFFFFFL; String s = "0xFFFFFFFFFFFFFFFF"; assertEquals(i, ParseLong.parseHex(s)); }
@Test public void testParseHex() throws Exception { long i = 123456; String s = Long.toHexString(i); assertEquals(i, ParseLong.parseHex(s)); }