### Question:
ByteUtils { public static byte[] newByteArray(byte[] data, int finalSize) { if (data == null) throw new NullPointerException("Data cannot be null."); if (finalSize < 0) throw new IllegalArgumentException("Final size must be equal or greater than 0."); if (finalSize == 0) return new byte[0]; byte[] filledArray = new byte[finalSize]; int diff = finalSize - data.length; if (diff >= 0) { for (int i = 0; i < diff; i++) filledArray[i] = '0'; System.arraycopy(data, 0, filledArray, diff, data.length); } else System.arraycopy(data, 0, filledArray, 0, finalSize); return filledArray; }  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 testNewByteArrayNullByteArray() { exception.expect(NullPointerException.class); exception.expectMessage(is(equalTo("Data cannot be null."))); ByteUtils.newByteArray(null, 1); }
@Test public final void testNewByteArrayNegativeSize() { exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Final size must be equal or greater than 0."))); ByteUtils.newByteArray(new byte[0], -5); }
@Test public final void testNewByteArrayEmptyByteArray() { byte[] expectedResult = new byte[]{'0', '0'}; byte[] result = ByteUtils.newByteArray(new byte[0], expectedResult.length); assertThat("Result byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testNewByteArrayZeroFinalSize() { byte[] original = new byte[]{'1', '2', '3', '4'}; byte[] expectedResult = new byte[0]; byte[] result = ByteUtils.newByteArray(original, 0); assertThat("Result byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testNewByteArrayFinalSizeLessThanOriginal() { byte[] original = new byte[]{'1', '2', '3', '4'}; byte[] expectedResult = new byte[]{'1'}; byte[] result = ByteUtils.newByteArray(original, 1); assertThat("Result byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testNewByteArrayFinalSizeSameAsOriginal() { byte[] original = new byte[]{'1', '2', '3', '4'}; byte[] expectedResult = new byte[]{'1', '2', '3', '4'}; byte[] result = ByteUtils.newByteArray(original, 4); assertThat("Result byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testNewByteArrayFinalSizeGreaterThanOriginal() { byte[] original = new byte[]{'1', '2', '3', '4'}; byte[] expectedResult = new byte[]{'0', '0', '1', '2', '3', '4'}; byte[] result = ByteUtils.newByteArray(original, 6); assertThat("Result byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }