### Question:
ByteUtils { public static int readIntegerFromByte(byte containerByte, int bitOffset, int bitLength) { if (bitOffset < 0 || bitOffset > 7) throw new IllegalArgumentException("Offset must be between 0 and 7."); if (bitLength < 0 || bitLength > 7) throw new IllegalArgumentException("Length must be between 0 and 8."); int readInteger = 0; for (int i = 0; i < bitLength; i++) { if (bitOffset + i > 7) break; if (isBitEnabled(containerByte, bitOffset + i)) readInteger = readInteger | (int)Math.pow(2, i); } return readInteger; }  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 testReadIntegerFromByteNegativeOffset() { exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Offset must be between 0 and 7."))); ByteUtils.readIntegerFromByte((byte)25, -8, 1); }
@Test public final void testReadIntegerFromByteOffsetGreaterThanLen() { exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Offset must be between 0 and 7."))); ByteUtils.readIntegerFromByte((byte)25, 100, 1); }
@Test public final void testReadIntegerFromByteNegativeLength() { exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Length must be between 0 and 8."))); ByteUtils.readIntegerFromByte((byte)25, 0, -1); }
@Test public final void testReadIntegerFromByteLengthGreaterThan8() { exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Length must be between 0 and 8."))); ByteUtils.readIntegerFromByte((byte)25, 0, 100); }
@Test public final void testReadIntegerFromByteOffsetLengthPlusOffsetBiggerThan8() { int expectedResult = 3; int result = ByteUtils.readIntegerFromByte((byte)54, 4, 5); assertThat("Returned int must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }
@Test public final void testReadIntegerFromByteOffset() { int expectedResult = 0xB; int result = ByteUtils.readIntegerFromByte((byte)0x36 , 1, 4); assertThat("Returned int must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); }