### Question:
ByteUtils { public static short byteArrayToShort(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 < 2) { values = new byte[2]; values[1] = byteArray[0]; values[0] = 0; } return (short) (((values[0] << 8) & 0xFF00) | values[1] & 0x00FF); }  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 testByteArrayToShortNullArray() { byte[] byteArray = null; exception.expect(NullPointerException.class); exception.expectMessage(is(equalTo("Byte array cannot be null."))); ByteUtils.byteArrayToShort(byteArray); }
@Test public final void testByteArrayToShortEmptyArray() { byte[] byteArray = new byte[0]; short expectedResult = 0; short result = ByteUtils.byteArrayToShort(byteArray); assertThat("Returned int must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testByteArrayToShortLessThan2Bytes() { byte[] byteArray = new byte[]{0x12}; short expectedResult = 0x12; short result = ByteUtils.byteArrayToShort(byteArray); assertThat("Returned short must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testByteArrayToShort2Bytes() { byte[] byteArray = new byte[]{0x12, 0x34}; short expectedResult = 0x1234; short result = ByteUtils.byteArrayToShort(byteArray); assertThat("Returned short must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testByteArrayToShortMoreThan2Bytes() { byte[] byteArray = new byte[]{0x12, 0x34, (byte)0x85, (byte)0x96}; short expectedResult = 0x1234; short result = ByteUtils.byteArrayToShort(byteArray); assertThat("Returned short must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }