### Question:
AbstractStatefulHash implements StatefulHash { @Override public byte[] getBytes() { final byte[] array = new byte[length()]; writeBytes(array, 0, array.length); return array; }  @Override boolean supportsUnsafe(); @Override void update(byte[] input); @Override void update(byte[] input, int index, int length); @Override void update(ByteBuffer input); @Override void update(long address, long length); @Override byte[] getBytes(); @Override int getBytes(byte[] output, int index, int maxLength); @Override byte getByte(); @Override short getShort();  }### Answer:
@Test public void testGetBytes() { final List<byte[]> captures = new ArrayList<>(); when(hash.length()).thenReturn(5); doAnswer(invocationOnMock -> { captures.add(invocationOnMock.getArgument(0)); return invocationOnMock.callRealMethod(); }).when(hash).writeBytes(any(byte[].class), eq(0), eq(5)); hash.getBytes(); assertEquals(5, captures.get(0).length); }
@Test public void testGetBytesByteArrayInt() { final byte[] output = new byte[5]; when(hash.length()).thenReturn(output.length); when(hash.getLong()).thenReturn(0x1234567890L); hash.getBytes(output, 0, output.length); assertArrayEquals(new byte[] { (byte) 0x90, 0x78, 0x56, 0x34, 0x12 }, output); }
@Test(expected = IndexOutOfBoundsException.class) public void testGetBytesByteArrayNegInt() { final byte[] output = new byte[5]; when(hash.length()).thenReturn(output.length); hash.getBytes(output, -1, output.length); verify(hash, atLeast(0)).length(); }
@Test(expected = IndexOutOfBoundsException.class) public void testGetBytesByteArrayIntOverflow() { final byte[] output = new byte[5]; hash.getBytes(output, 0, output.length + 1); }