### Question:
ArrayUtils { public static byte[] toByteArray(final BigInteger value, final int numBytes) { final byte[] outputBytes = new byte[numBytes]; final byte[] bigIntegerBytes = value.toByteArray(); int copyStartIndex = (0x00 == bigIntegerBytes[0]) ? 1 : 0; int numBytesToCopy = bigIntegerBytes.length - copyStartIndex; if (numBytesToCopy > numBytes) { copyStartIndex += numBytesToCopy - numBytes; numBytesToCopy = numBytes; } for (int i = 0; i < numBytesToCopy; ++i) { outputBytes[i] = bigIntegerBytes[copyStartIndex + numBytesToCopy - i - 1]; } return outputBytes; } private  ArrayUtils(); static byte[] duplicate(final byte[] src); static byte[] concat(final byte[]... arrays); static byte[][] split(final byte[] bytes, final int splitIndex); static byte[] toByteArray(final BigInteger value, final int numBytes); static BigInteger toBigInteger(final byte[] bytes); static int isEqualConstantTime(final byte[] b, final byte[] c); static int compare(final byte[] b, final byte[] c); static int getBit(final byte[] h, final int i);  }### Answer:
@Test public void canConvertPositiveBigIntegerToByteArray() { final byte[] bytes = ArrayUtils.toByteArray(new BigInteger("321495", 16), 3); MatcherAssert.assertThat(bytes, IsEqual.equalTo(new byte[] {(byte) 0x95, 0x14, 0x32})); }
@Test public void canConvertNegativeBigIntegerToByteArray() { final byte[] bytes = ArrayUtils.toByteArray(new BigInteger("F21495", 16), 3); MatcherAssert.assertThat(bytes, IsEqual.equalTo(new byte[] {(byte) 0x95, 0x14, (byte) 0xF2})); }
@Test public void canConvertBigIntegerWithLeadingZerosToByteArray() { final byte[] bytes = ArrayUtils.toByteArray(new BigInteger("0000A5", 16), 3); MatcherAssert.assertThat(bytes, IsEqual.equalTo(new byte[] {(byte) 0xA5, 0x00, 0x00})); }
@Test public void byteArrayConversionTruncatesLargeInteger() { final byte[] bytes = ArrayUtils.toByteArray(new BigInteger("F122321495", 16), 3); MatcherAssert.assertThat(bytes, IsEqual.equalTo(new byte[] {(byte) 0x95, 0x14, 0x32})); }