### Question:
LeftPaddedIdentityHasher implements Hasher { @Override public void hash(ByteBuffer value, int hashSize, byte[] hashBytes) { if (value.remaining() > hashSize) { throw new IllegalArgumentException("Cannot pad incoming item "+value+" to length "+hashSize+"!"); } int bytesToPad = hashSize - value.remaining(); System.arraycopy(value.array(), value.arrayOffset() + value.position(), hashBytes, bytesToPad, value.remaining()); }  @Override void hash(ByteBuffer value, int hashSize, byte[] hashBytes);  }### Answer:
@Test public void testPad() throws Exception { LeftPaddedIdentityHasher hasher = new LeftPaddedIdentityHasher(); byte[] result = new byte[4]; hasher.hash(ByteBuffer.wrap(new byte[]{1, 2}), 4, result); assertTrue(Arrays.equals(new byte[]{0,0,1,2}, result)); byte[] result2 = new byte[4]; hasher.hash(ByteBuffer.wrap(new byte[]{1, 2, 3, 4}), 4, result2); assertTrue(Arrays.equals(new byte[]{1, 2, 3, 4}, result2)); try{ byte[] result3 = new byte[4]; hasher.hash(ByteBuffer.wrap(new byte[]{1, 2, 3, 4, 5}), 4, result3); fail(); }catch(Exception e){ } }