### Question:
DescriptorDigest { public static DescriptorDigest fromHash(String hash) throws DigestException { if (!hash.matches(HASH_REGEX)) { throw new DigestException("Invalid hash: " + hash); } return new DescriptorDigest(hash); } private  DescriptorDigest(String hash); static DescriptorDigest fromHash(String hash); static DescriptorDigest fromDigest(String digest); String getHash(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final int HASH_LENGTH; }### Answer:
@Test public void testCreateFromHash_fail() { String badHash = "not a valid hash"; try { DescriptorDigest.fromHash(badHash); Assert.fail("Invalid hash should have caused digest creation failure."); } catch (DigestException ex) { Assert.assertEquals("Invalid hash: " + badHash, ex.getMessage()); } }
@Test public void testCreateFromHash_failIncorrectLength() { String badHash = createGoodHash('a') + 'a'; try { DescriptorDigest.fromHash(badHash); Assert.fail("Invalid hash should have caused digest creation failure."); } catch (DigestException ex) { Assert.assertEquals("Invalid hash: " + badHash, ex.getMessage()); } }