### Question:
ByteUtils { public static int byteArrayToInt(byte[] byteArray) { if (byteArray == null) throw new NullPointerException("Byte array cannot be null."); if (byteArray.length == 0) return 0; byte[] values = byteArray; if (byteArray.length < 4) { values = new byte[4]; int diff = values.length - byteArray.length; for (int i = 0; i < diff; i++) values[i] = 0; for (int i = diff; i < values.length; i++) values[i] = byteArray[i - diff]; } return ((values[0] & 0xFF) << 24) | ((values[1] & 0xFF) << 16) | ((values[2] & 0xFF) << 8) | (values[3] & 0xFF); }  static byte[] readBytes(int numBytes, ByteArrayInputStream inputStream); static String readString(ByteArrayInputStream inputStream); static byte[] longToByteArray(long value); static long byteArrayToLong(byte[] byteArray); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] byteArray); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] byteArray); static byte[] stringToByteArray(String value); static String byteArrayToString(byte[] value); static int byteToInt(byte b); static boolean isBitEnabled(int containerInteger, int bitPosition); static int readIntegerFromByte(byte containerByte, int bitOffset, int bitLength); static boolean readBooleanFromByte(byte containerByte, int bitOffset); static byte[] readUntilCR(ByteArrayInputStream inputStream); static byte[] newByteArray(byte[] data, int finalSize); static byte[] swapByteArray(byte[] source);  }### Answer:
@Test public final void testByteArrayToIntNullArray() { byte[] byteArray = null; exception.expect(NullPointerException.class); exception.expectMessage(is(equalTo("Byte array cannot be null."))); ByteUtils.byteArrayToInt(byteArray); }
@Test public final void testByteArrayToIntEmptyArray() { byte[] byteArray = new byte[0]; int expectedResult = 0; int result = ByteUtils.byteArrayToInt(byteArray); assertThat("Returned int must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testByteArrayToIntLessThan4Bytes() { byte[] byteArray = new byte[]{0x12, 0x34}; int expectedResult = 0x1234; int result = ByteUtils.byteArrayToInt(byteArray); assertThat("Returned int must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testByteArrayToInt4Bytes() { byte[] byteArray = new byte[]{0x12, 0x34, (byte)0x85, (byte)0x96}; int expectedResult = 0x12348596; int result = ByteUtils.byteArrayToInt(byteArray); assertThat("Returned int must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testByteArrayToIntMoreThan4Bytes() { byte[] byteArray = new byte[]{0x12, 0x34, (byte)0x85, (byte)0x96, 0x23, 0x47, 0x56, 0x20, 0x63, 0x67}; int expectedResult = 0x12348596; int result = ByteUtils.byteArrayToInt(byteArray); assertThat("Returned int must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }