コード例 #1
0
 @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));
 }
コード例 #2
0
 //  Test prefix with no value reject
 @Test(expected = NumberFormatException.class)
 public void testParseHex_PrefixNoValue() throws Exception {
   String s = "0x";
   ParseLong.parseHex(s);
 }
コード例 #3
0
 //  Test positive sign prefix reject (no prefix)
 @Test(expected = NumberFormatException.class)
 public void testParseHex_Positive3() throws Exception {
   String s = "+12AB";
   ParseLong.parseHex(s);
 }
コード例 #4
0
 //  Test null
 @Test(expected = NumberFormatException.class)
 public void testParseHex_Null() throws Exception {
   ParseLong.parseHex(null);
 }
コード例 #5
0
 //  Test bad
 @Test(expected = NumberFormatException.class)
 public void testParseHex_Bad() throws Exception {
   ParseLong.parseHex("12AB-**&1'");
 }
コード例 #6
0
 //  Test negative sign prefix reject (after prefix)
 @Test(expected = NumberFormatException.class)
 public void testParseHex_Negative2() throws Exception {
   String s = "0x-12AC";
   ParseLong.parseHex(s);
 }
コード例 #7
0
 //  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));
 }
コード例 #8
0
 //  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);
 }
コード例 #9
0
 @Test
 public void testParseHexMaxUnsigned() throws Exception {
   long i = 0xFFFFFFFFFFFFFFFFL;
   String s = "0xFFFFFFFFFFFFFFFF";
   assertEquals(i, ParseLong.parseHex(s));
 }
コード例 #10
0
 @Test
 public void testParseHex() throws Exception {
   long i = 123456;
   String s = Long.toHexString(i);
   assertEquals(i, ParseLong.parseHex(s));
 }