ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) return i; i++; } return i; }  static byte[] appendByte(byte[] bytes, byte b); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static String toHexString(byte[] data); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static byte[] encodeValFor32Bits(Object arg); static byte[] encodeDataList(Object... args); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] merge(byte[]... arrays); static boolean isNullOrZeroArray(byte[] array); static boolean isSingleZero(byte[] array); static Set<byte[]> difference(Set<byte[]> setA, Set<byte[]> setB); static int length(byte[]... bytes); static final byte[] EMPTY_BYTE_ARRAY; static final byte[] ZERO_BYTE_ARRAY; }
@Test public void testMatchingNibbleLength1() { byte[] a = new byte[]{0x00, 0x01}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); }
@Test public void testMatchingNibbleLength2() { byte[] a = new byte[]{0x00}; byte[] b = new byte[]{0x00, 0x01}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); }
@Test public void testMatchingNibbleLength3() { byte[] a = new byte[]{0x00}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); }
@Test public void testMatchingNibbleLength4() { byte[] a = new byte[]{0x01}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(0, result); }
@Test(expected = NullPointerException.class) public void testMatchingNibbleLength5() { byte[] a = null; byte[] b = new byte[]{0x00}; ByteUtil.matchingNibbleLength(a, b); }
@Test(expected = NullPointerException.class) public void testMatchingNibbleLength6() { byte[] a = new byte[]{0x00}; byte[] b = null; ByteUtil.matchingNibbleLength(a, b); }
@Test public void testMatchingNibbleLength7() { byte[] a = new byte[0]; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(0, result); }