@@ -227,7 +227,9 @@ void testBinaryToHexDigitMsb0_4bits_2args() {
227227 final boolean [] javaDocCheck = {
228228 true , false , false , true , true , false , true , false };
229229 assertEquals ('d' , Conversion .binaryToHexDigitMsb0_4bits (javaDocCheck , 3 ));
230-
230+ final boolean [] nineValuesBooleanArray = {
231+ true , false , false , true , true , false , true , false , true };
232+ assertIllegalArgumentException (() -> Conversion .binaryToHexDigitMsb0_4bits (nineValuesBooleanArray , 3 ));
231233 }
232234
233235 /**
@@ -312,6 +314,7 @@ void testBinaryToInt() {
312314 assertEquals (0x01C0F1FD , Conversion .binaryToInt (src , 1 * 4 , 0 , 0 , 8 * 4 ));
313315 assertEquals (0x12345679 , Conversion .binaryToInt (src , 0 * 4 , 0x12345679 , 0 , 0 * 4 ));
314316 assertEquals (0x87645679 , Conversion .binaryToInt (src , 15 * 4 , 0x12345679 , 20 , 3 * 4 ));
317+ assertIllegalArgumentException (() -> Conversion .binaryToInt (src , 15 * 4 , 0x12345679 , 20 , Integer .SIZE ));
315318 }
316319
317320 /**
@@ -336,6 +339,7 @@ void testBinaryToLong() {
336339 assertEquals (
337340 0x1234567876BCDEF0L ,
338341 Conversion .binaryToLong (src , 15 * 4 , 0x123456798ABCDEF0L , 24 , 3 * 4 ));
342+ assertIllegalArgumentException (() -> Conversion .binaryToLong (src , 15 * 4 , 0x123456798ABCDEF0L , 24 , Long .SIZE ));
339343 }
340344
341345 /**
@@ -359,6 +363,7 @@ void testBinaryToShort() {
359363 (short ) 0x1234 , Conversion .binaryToShort (src , 0 * 4 , (short ) 0x1234 , 0 , 0 * 4 ));
360364 assertEquals (
361365 (short ) 0x8764 , Conversion .binaryToShort (src , 15 * 4 , (short ) 0x1234 , 4 , 3 * 4 ));
366+ assertIllegalArgumentException (() -> Conversion .binaryToShort (src , 15 * 4 , (short ) 0x1234 , 4 , Short .SIZE ));
362367 }
363368
364369 /**
@@ -376,6 +381,7 @@ void testByteArrayToInt() {
376381 assertEquals (0x12345678 , Conversion .byteArrayToInt (src , 0 , 0x12345678 , 0 , 0 ));
377382 assertEquals (0xCD345678 , Conversion .byteArrayToInt (src , 0 , 0x12345678 , 24 , 1 ));
378383 // assertEquals(0x56341278, Conversion.ByteArrayToInt(src, 5, 0x01234567, 8, 4));
384+ assertIllegalArgumentException (() -> Conversion .byteArrayToInt (src , 0 , 0x12345678 , 24 , Integer .SIZE ));
379385 }
380386
381387 /**
@@ -396,6 +402,7 @@ void testByteArrayToLong() {
396402 0x12345678CDBCDEF0L , Conversion .byteArrayToLong (src , 0 , 0x123456789ABCDEF0L , 24 , 1 ));
397403 assertEquals (
398404 0x123456789A7856F0L , Conversion .byteArrayToLong (src , 7 , 0x123456789ABCDEF0L , 8 , 2 ));
405+ assertIllegalArgumentException (() -> Conversion .byteArrayToLong (src , 7 , 0x123456789ABCDEF0L , 8 , Long .SIZE ));
399406 }
400407
401408 /**
@@ -414,6 +421,7 @@ void testByteArrayToShort() {
414421 assertEquals ((short ) 0xCD34 , Conversion .byteArrayToShort (src , 0 , (short ) 0x1234 , 8 , 1 ));
415422 // assertEquals((short) 0x5678, Conversion.ByteArrayToShort(src, 7, (short) 0x0123, 8,
416423 // 2));
424+ assertIllegalArgumentException (() -> Conversion .byteArrayToShort (src , 0 , (short ) 0x1234 , 8 , Short .SIZE ));
417425 }
418426
419427 /**
@@ -439,6 +447,10 @@ void testByteArrayToUuid() {
439447 0 , 0 , (byte ) 0x88 , (byte ) 0x99 , (byte ) 0xaa , (byte ) 0xbb , (byte ) 0xcc , (byte ) 0xdd ,
440448 (byte ) 0xee , (byte ) 0xff , (byte ) 0x00 , (byte ) 0x11 , (byte ) 0x22 , (byte ) 0x33 ,
441449 (byte ) 0x44 , (byte ) 0x55 , (byte ) 0x66 , (byte ) 0x77 }, 2 ));
450+ assertIllegalArgumentException (() -> Conversion .byteArrayToUuid (new byte []{
451+ 0 , 0 , (byte ) 0x88 , (byte ) 0x99 , (byte ) 0xaa , (byte ) 0xbb , (byte ) 0xcc , (byte ) 0xdd ,
452+ (byte ) 0xee , (byte ) 0xff , (byte ) 0x00 , (byte ) 0x11 , (byte ) 0x22 , (byte ) 0x33 ,
453+ (byte ) 0x44 , (byte ) 0x55 , (byte ) 0x66 , (byte ) 0x77 }, 3 ));
442454 }
443455
444456 /**
@@ -487,6 +499,7 @@ void testByteToBinary() {
487499 assertArrayEquals (new boolean []{
488500 false , false , false , true , false , true , false , false , true , false , false , false ,
489501 false }, Conversion .byteToBinary ((byte ) 0x95 , 2 , new boolean [13 ], 3 , 6 ));
502+ assertIllegalArgumentException (() -> Conversion .byteToBinary ((byte ) 0x95 , 2 , new boolean [13 ], 3 , Byte .SIZE ));
490503 }
491504
492505 /**
@@ -510,6 +523,7 @@ void testByteToHex() {
510523 assertEquals ("000e0" , Conversion .byteToHex ((byte ) 0xEF , 4 , "00000" , 3 , 1 ));
511524 assertEquals ("fe" , Conversion .byteToHex ((byte ) 0xEF , 0 , "" , 0 , 2 ));
512525 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .byteToHex ((byte ) 0xEF , 0 , "" , 1 , 2 ));
526+ assertIllegalArgumentException (() -> Conversion .byteToHex ((byte ) 0xEF , 0 , "" , 1 , Byte .SIZE ));
513527 }
514528
515529 /**
@@ -708,6 +722,7 @@ void testHexToInt() {
708722 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToInt (src , src .length (), 0 , 0 , 1 ));
709723 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToInt (src , Integer .MIN_VALUE , 0 , 0 , 1 ));
710724 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToInt (src , Integer .MAX_VALUE , 0 , 0 , 1 ));
725+ assertIllegalArgumentException (() -> Conversion .hexToInt (src , Integer .MAX_VALUE , 0 , 0 , Integer .SIZE ));
711726 }
712727
713728 /**
@@ -725,6 +740,7 @@ void testHexToLong() {
725740 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToLong (src , src .length (), 0 , 0 , 1 ));
726741 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToLong (src , Integer .MIN_VALUE , 0 , 0 , 1 ));
727742 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToLong (src , Integer .MAX_VALUE , 0 , 0 , 1 ));
743+ assertIllegalArgumentException (() -> Conversion .hexToLong (src , Integer .MAX_VALUE , 0 , 0 , Long .SIZE ));
728744 }
729745
730746 /**
@@ -742,6 +758,7 @@ void testHexToShort() {
742758 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToShort (src , src .length (), (short ) 0 , 0 , 1 ));
743759 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToShort (src , Integer .MIN_VALUE , (short ) 0 , 0 , 1 ));
744760 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .hexToShort (src , Integer .MAX_VALUE , (short ) 0 , 0 , 1 ));
761+ assertIllegalArgumentException (() -> Conversion .hexToShort (src , Integer .MAX_VALUE , (short ) 0 , 0 , Short .SIZE ));
745762 }
746763
747764 /**
@@ -760,6 +777,7 @@ void testIntArrayToLong() {
760777 assertEquals (
761778 0x1234567878000000L , Conversion .intArrayToLong (src , 2 , 0x123456789ABCDEF0L , 0 , 1 ));
762779 // assertEquals(0x0F12345678000000L, Conversion.intsToLong(src, 1, 0x123456789ABCDEF0L, 32, 2));
780+ assertIllegalArgumentException (() -> Conversion .intArrayToLong (src , 2 , 0x123456789ABCDEF0L , 0 , Long .SIZE ));
763781 }
764782
765783 /**
@@ -837,6 +855,7 @@ void testIntToBinary() {
837855 true , false , false , true , true , true , true , false , true , false , true , false ,
838856 true , false , false , false , false , true , false , false , true , false , false ,
839857 false , false }, Conversion .intToBinary (0x90ABCDEF , 2 , new boolean [37 ], 3 , 30 ));
858+ assertIllegalArgumentException (() -> Conversion .intToBinary (0x90ABCDEF , 2 , new boolean [0 ], 3 , Integer .SIZE ));
840859 }
841860
842861 /**
@@ -919,6 +938,7 @@ void testIntToByteArray() {
919938 (byte ) 0xFF , (byte ) 0xFF , (byte ) 0xFF , (byte ) 0xFF , (byte ) 0xFF },
920939 Conversion .intToByteArray (0x90ABCDEF , 13 , new byte []{
921940 -1 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 }, 3 , 3 ));
941+ assertIllegalArgumentException (() -> Conversion .intToByteArray (0x90ABCDEF , 13 , new byte []{}, 3 , Integer .SIZE ));
922942 }
923943
924944 /**
@@ -978,6 +998,7 @@ void testIntToHex() {
978998 Conversion .intToHex (0x90ABCDEF , 4 , "ffffffffffffffffffffffff" , 3 , 7 ));
979999 assertEquals ("fedcba09" , Conversion .intToHex (0x90ABCDEF , 0 , "" , 0 , 8 ));
9801000 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .intToHex (0x90ABCDEF , 0 , "" , 1 , 8 ));
1001+ assertIllegalArgumentException (() -> Conversion .intToHex (0x90ABCDEF , 0 , "" , 0 , Integer .SIZE / 4 + 1 ));
9811002 }
9821003
9831004 /**
@@ -1087,6 +1108,7 @@ void testIntToShortArray() {
10871108 assertArrayEquals (
10881109 new short []{(short ) 0x091A },
10891110 Conversion .intToShortArray (0x12345678 , 17 , new short []{0 }, 0 , 1 ));
1111+ assertIllegalArgumentException (() -> Conversion .intToShortArray (0x12345678 , 17 , new short []{0 }, 0 , Integer .SIZE / Short .SIZE + 1 ));
10901112 }
10911113
10921114 /**
@@ -1210,6 +1232,7 @@ void testLongToBinary() {
12101232 true , false , false , false , true , false , true , true , false , false , false , true ,
12111233 false , false , true , false , false , false , false , false , false , false },
12121234 Conversion .longToBinary (0x1234567890ABCDEFL , 2 , new boolean [69 ], 3 , 62 ));
1235+ assertIllegalArgumentException (() -> Conversion .longToBinary (0x1234567890ABCDEFL , 2 , new boolean [69 ], 3 , Long .SIZE - 1 ));
12131236 }
12141237
12151238 /**
@@ -1319,6 +1342,8 @@ void testLongToByteArray() {
13191342 (byte ) 0xB3 , (byte ) 0xA2 , (byte ) 0x91 , (byte ) 0x00 , (byte ) 0xFF },
13201343 Conversion .longToByteArray (0x1234567890ABCDEFL , 13 , new byte []{
13211344 -1 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 }, 3 , 7 ));
1345+ assertIllegalArgumentException (() -> Conversion .longToByteArray (0x1234567890ABCDEFL , 13 , new byte []{
1346+ -1 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 }, 3 , Long .SIZE / Byte .SIZE + 1 ));
13221347 }
13231348
13241349 /**
@@ -1379,6 +1404,7 @@ void testLongToHex() {
13791404 assertEquals (
13801405 "fedcba0987654321" , Conversion .longToHex (0x1234567890ABCDEFL , 0 , "" , 0 , 16 ));
13811406 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .longToHex (0x1234567890ABCDEFL , 0 , "" , 1 , 8 ));
1407+ assertIllegalArgumentException (() -> Conversion .longToHex (0x1234567890ABCDEFL , 0 , "" , 1 , Long .SIZE / 4 + 1 ));
13821408 }
13831409
13841410 /**
@@ -1434,6 +1460,7 @@ void testLongToIntArray() {
14341460 assertArrayEquals (
14351461 new int []{0x091A2B3C },
14361462 Conversion .longToIntArray (0x1234567890ABCDEFL , 33 , new int []{0 }, 0 , 1 ));
1463+ assertIllegalArgumentException (() -> Conversion .longToIntArray (0x1234567890ABCDEFL , 33 , new int []{0 }, 0 , Long .SIZE / Integer .SIZE + 1 ));
14371464 }
14381465
14391466 /**
@@ -1509,6 +1536,7 @@ void testLongToShortArray() {
15091536 assertArrayEquals (
15101537 new short []{(short ) 0x2B3C },
15111538 Conversion .longToShortArray (0x1234567890ABCDEFL , 33 , new short []{0 }, 0 , 1 ));
1539+ assertIllegalArgumentException (() -> Conversion .longToShortArray (0x1234567890ABCDEFL , 33 , new short []{0 }, 0 , Long .SIZE / Short .SIZE ));
15121540 }
15131541
15141542 /**
@@ -1525,6 +1553,7 @@ void testShortArrayToInt() {
15251553 assertEquals (0x12345678 , Conversion .shortArrayToInt (src , 0 , 0x12345678 , 0 , 0 ));
15261554 assertEquals (0xCDF15678 , Conversion .shortArrayToInt (src , 0 , 0x12345678 , 16 , 1 ));
15271555 // assertEquals(0x34567800, Conversion.ShortArrayToInt(src, 3, 0x12345678, 16, 2));
1556+ assertIllegalArgumentException (() -> Conversion .shortArrayToInt (src , 0 , 0x12345678 , 16 , Integer .SIZE / Short .SIZE ));
15281557 }
15291558
15301559 /**
@@ -1546,6 +1575,7 @@ void testShortArrayToLong() {
15461575 assertEquals (
15471576 0x123478003456DEF0L ,
15481577 Conversion .shortArrayToLong (src , 3 , 0x123456789ABCDEF0L , 16 , 2 ));
1578+ assertIllegalArgumentException (() -> Conversion .shortArrayToLong (src , 3 , 0x123456789ABCDEF0L , 16 , Long .SIZE / Short .SIZE ));
15491579 }
15501580
15511581 /**
@@ -1618,6 +1648,7 @@ void testShortToBinary() {
16181648 false , false , false , true , true , false , true , true , true , true , false , true ,
16191649 true , false , false , true , true , false , false , false , false },
16201650 Conversion .shortToBinary ((short ) 0xCDEF , 2 , new boolean [21 ], 3 , 14 ));
1651+ assertIllegalArgumentException (() -> Conversion .shortToBinary ((short ) 0xCDEF , 2 , new boolean [21 ], 3 , Short .SIZE - 1 ));
16211652 }
16221653
16231654 /**
@@ -1679,6 +1710,8 @@ void testShortToByteArray() {
16791710 (byte ) 0xFF , (byte ) 0x00 , (byte ) 0xFF , (byte ) 0xFE , (byte ) 0xFF , (byte ) 0xFF ,
16801711 (byte ) 0xFF }, Conversion .shortToByteArray ((short ) 0xCDEF , 13 , new byte []{
16811712 -1 , 0 , -1 , -1 , -1 , -1 , -1 }, 3 , 1 ));
1713+ assertIllegalArgumentException (() -> Conversion .shortToByteArray ((short ) 0xCDEF , 13 , new byte []{
1714+ -1 , 0 , -1 , -1 , -1 , -1 , -1 }, 3 , Short .SIZE / Byte .SIZE ));
16821715 }
16831716
16841717 /**
@@ -1726,6 +1759,7 @@ void testShortToHex() {
17261759 Conversion .shortToHex ((short ) 0xCDEF , 4 , "ffffffffffffffffffffffff" , 3 , 3 ));
17271760 assertEquals ("fedc" , Conversion .shortToHex ((short ) 0xCDEF , 0 , "" , 0 , 4 ));
17281761 assertThrows (StringIndexOutOfBoundsException .class , () -> Conversion .shortToHex ((short ) 0xCDEF , 0 , "" , 1 , 4 ));
1762+ assertIllegalArgumentException (() -> Conversion .shortToHex ((short ) 0xCDEF , 0 , "" , 1 , Short .SIZE / 4 + 1 ));
17291763 }
17301764
17311765 /**
@@ -1753,5 +1787,9 @@ void testUuidToByteArray() {
17531787 (byte ) 0xdd , (byte ) 0xee , (byte ) 0xff , (byte ) 0x00 , (byte ) 0x11 , (byte ) 0x22 , (byte ) 0x33 ,
17541788 (byte ) 0x00 , (byte ) 0x00 }, Conversion .uuidToByteArray (new UUID (
17551789 0xFFEEDDCCBBAA9988L , 0x7766554433221100L ), new byte [16 ], 2 , 12 ));
1790+ assertArrayEquals (new byte []{(byte ) 0x1 , (byte ) 0x2 }, Conversion .uuidToByteArray (new UUID (
1791+ 0xFFEEDDCCBBAA9988L , 0x7766554433221100L ), new byte []{(byte ) 0x1 , (byte ) 0x2 }, 2 , 0 ));
1792+ assertIllegalArgumentException (() -> Conversion .uuidToByteArray (new UUID (
1793+ 0xFFEEDDCCBBAA9988L , 0x7766554433221100L ), new byte [16 ], 2 , 17 ));
17561794 }
17571795}
0 commit comments