### Question:
ByteUtils { public static byte[] stringToByteArray(String value) { if (value == null) throw new NullPointerException("Value cannot be null."); return value.getBytes(); }  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 testStringToByteArrayNullString() { String s = null; exception.expect(NullPointerException.class); exception.expectMessage(is(equalTo("Value cannot be null."))); ByteUtils.stringToByteArray(s); }
@Test public final void testStringToByteArrayEmptyString() { String s = ""; byte[] result = ByteUtils.stringToByteArray(s); assertThat("Returned byte array must be empty", result.length, is(equalTo(0))); }
@Test public final void testStringToByteArray() { String s = "Hello"; byte[] expectedResult = new byte[]{'H', 'e', 'l', 'l', 'o'}; byte[] result = ByteUtils.stringToByteArray(s); assertThat("Returned byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }