### Question:
DeadEndDigestOutputStream extends DigestOutputStream { public String getDigestString() { byte[] digestBytes = getMessageDigest().digest(); StringBuffer sb = new StringBuffer(); for (byte b : digestBytes) { sb.append(String.format("%02x", b & 0xff)); } return sb.toString(); } DeadEndDigestOutputStream(); String getDigestString();  }### Answer:
@Test public void testDigestIsDeterministic() throws java.io.IOException { DeadEndDigestOutputStream stream1 = new DeadEndDigestOutputStream(); DeadEndDigestOutputStream stream2 = new DeadEndDigestOutputStream(); assertEquals(stream1.getDigestString(), stream2.getDigestString()); stream1.write(123); stream2.write(123); assertEquals(stream1.getDigestString(), stream2.getDigestString()); stream1.close(); stream2.close(); }
@Test public void testDigestChangesOnWrite() throws java.io.IOException { DeadEndDigestOutputStream stream = new DeadEndDigestOutputStream(); String originalDigest = stream.getDigestString(); stream.write(123); assertThat(originalDigest, not(equalTo(stream.getDigestString()))); stream.close(); }