### Question:
Numeric { public static String encodeQuantity(BigInteger value) { if (value.signum() != -1) { return HEX_PREFIX + value.toString(16); } else { throw new MessageEncodingException("Negative values are not supported"); } } private  Numeric(); static String encodeQuantity(BigInteger value); static BigInteger decodeQuantity(String value); static String cleanHexPrefix(String input); static String prependHexPrefix(String input); static boolean containsHexPrefix(String input); static BigInteger toBigInt(byte[] value, int offset, int length); static BigInteger toBigInt(byte[] value); static BigInteger toBigInt(String hexValue); static BigInteger toBigIntNoPrefix(String hexValue); static String toHexStringWithPrefix(BigInteger value); static String toHexStringNoPrefix(BigInteger value); static String toHexStringNoPrefix(byte[] input); static String toHexStringWithPrefixZeroPadded(BigInteger value, int size); static String toHexStringWithPrefixSafe(BigInteger value); static String toHexStringNoPrefixZeroPadded(BigInteger value, int size); static byte[] toBytesPadded(BigInteger value, int length); static byte[] hexStringToByteArray(String input); static String toHexString(byte[] input, int offset, int length, boolean withPrefix); static String toHexString(byte[] input); static byte asByte(int m, int n); static boolean isIntegerValue(BigDecimal value);  }### Answer:
@Test public void testQuantityEncode() { assertThat(Numeric.encodeQuantity(BigInteger.valueOf(0)), is("0x0")); assertThat(Numeric.encodeQuantity(BigInteger.valueOf(1)), is("0x1")); assertThat(Numeric.encodeQuantity(BigInteger.valueOf(1024)), is("0x400")); assertThat(Numeric.encodeQuantity( BigInteger.valueOf(Long.MAX_VALUE)), is("0x7fffffffffffffff")); assertThat(Numeric.encodeQuantity( new BigInteger("204516877000845695339750056077105398031")), is("0x99dc848b94efc27edfad28def049810f")); }
@Test(expected = MessageEncodingException.class) public void testQuantityEncodeNegative() { Numeric.encodeQuantity(BigInteger.valueOf(-1)); }
@Test public void testQuantityEncode() { assertEquals(Numeric.encodeQuantity(BigInteger.valueOf(0)), ("0x0")); assertEquals(Numeric.encodeQuantity(BigInteger.valueOf(1)), ("0x1")); assertEquals(Numeric.encodeQuantity(BigInteger.valueOf(1024)), ("0x400")); assertEquals( Numeric.encodeQuantity(BigInteger.valueOf(Long.MAX_VALUE)), ("0x7fffffffffffffff")); assertEquals( Numeric.encodeQuantity(new BigInteger("204516877000845695339750056077105398031")), ("0x99dc848b94efc27edfad28def049810f")); }
@Test public void testQuantityEncodeNegative() { assertThrows( MessageEncodingException.class, () -> Numeric.encodeQuantity(BigInteger.valueOf(-1))); }