ByteValue implements ByteReadable { public static void checkUnsignedBounds(long value, int numberOfBytes) { double upperBound = Math.pow((double) 2, (double) (8 * numberOfBytes)); if (value < 0 || value >= upperBound) { throw new IllegalArgumentException("Value must between 0 and " + upperBound + ". Was " + value); } } protected  ByteValue(byte... value); protected  ByteValue(ByteBuf byteBuf); static void checkUnsignedBounds(long value, int numberOfBytes); static void checkUnsignedBounds(BigInteger value, int numberOfBytes); @Override byte[] getBytes(); @Override ByteBuf getByteBuf(); @Override long getCalculatedLength(); static ByteValue of(byte... values); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void checkUnsignedBoundsLong() { ByteValue.checkUnsignedBounds(0, 4); ByteValue.checkUnsignedBounds(upperBound - 1, 4); }
@Test public void checkUnsignedBoundsLongHex() { ByteValue.checkUnsignedBounds(0x0_00_00, 2); ByteValue.checkUnsignedBounds(0x0_FF_FF, 2); }
@Test(expected = IllegalArgumentException.class) public void checkUnsignedBoundsLongNegative() { ByteValue.checkUnsignedBounds(-1, 4); }
@Test(expected = IllegalArgumentException.class) public void checkUnsignedBoundsLongTooBig() { ByteValue.checkUnsignedBounds(upperBound, 4); }
@Test(expected = IllegalArgumentException.class) public void checkUnsignedBoundsLongTooBigHex() { ByteValue.checkUnsignedBounds(0x1_00_00, 2); }
@Test public void checkUnsignedBoundsBigHex() { ByteValue.checkUnsignedBounds(BigInteger.valueOf(0x0_00_00), 2); ByteValue.checkUnsignedBounds(BigInteger.valueOf(0x0_FF_FF), 2); }
@Test(expected = IllegalArgumentException.class) public void checkUnsignedBoundsBigNegative() { ByteValue.checkUnsignedBounds(new BigInteger("-1"), 4); }
@Test(expected = IllegalArgumentException.class) public void checkUnsignedBoundsBigTooBigHex() { ByteValue.checkUnsignedBounds(BigInteger.valueOf(0x1_00_00), 2); }