### Question:
ByteUtils { public static byte[] swapByteArray(byte[] source) { if (source == null) throw new NullPointerException("Source cannot be null."); if (source.length == 0) return new byte[0]; byte[] swapped = new byte[source.length]; for (int i = 0; i < source.length; i++) swapped[source.length - i - 1] = source[i]; return swapped; }  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 testSwapByteArrayNullByteArray() { exception.expect(NullPointerException.class); exception.expectMessage(is(equalTo("Source cannot be null."))); ByteUtils.swapByteArray(null); }
@Test public final void testSwapByteArrayEmptyArray() { byte[] original = new byte[0]; byte[] expectedResult = new byte[0]; byte[] result = ByteUtils.swapByteArray(original); assertThat("Result byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testSwapByteArray() { byte[] original = new byte[] {'B', 'y', 'e', ' ', 'm', 'y', ' ', 'f', 'r', 'i', 'e', 'n', 'd'}; byte[] expectedResult = new byte[]{'d', 'n', 'e', 'i', 'r', 'f', ' ', 'y', 'm', ' ', 'e', 'y', 'B'}; byte[] result = ByteUtils.swapByteArray(original); assertThat("Result byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }