### Question:
Digest extends AbstractDigest { public static Digest fromString(final String digest) { return new Digest(algorithmFromString(digest), digestFromString(digest)); } Digest(final DigestAlgorithm algorithm, final byte[] digest);  Digest(final byte[] digest); protected  Digest(); @Override DigestAlgorithm getAlgorithm(); @Override byte[] getDigest(); OptionalDigest asOptionalDigest(); static Digest fromString(final String digest); static final Digest SHA1_ZERO; static final Digest SHA1_OF_NO_DATA; }### Answer:
@Test public final void testFromStringMD2() { final byte[] digestBytes = getTestDigest(16); Digest digest = new Digest(DigestAlgorithm.MD2, digestBytes); String digestString = digest.toString(); Digest digestFromString = Digest.fromString(digestString); Assert.assertEquals(digestFromString, digest); }
@Test public final void testFromStringMD5() { final byte[] digestBytes = getTestDigest(16); Digest digest = new Digest(DigestAlgorithm.MD5, digestBytes); String digestString = digest.toString(); Digest digestFromString = Digest.fromString(digestString); Assert.assertEquals(digestFromString, digest); }
@Test public final void testFromStringSHA1() { final byte[] digestBytes = getTestDigest(20); Digest digest = new Digest(DigestAlgorithm.SHA1, digestBytes); String digestString = digest.toString(); Digest digestFromString = Digest.fromString(digestString); Assert.assertEquals(digestFromString, digest); }
@Test public final void testFromStringSHA256() { final byte[] digestBytes = getTestDigest(32); Digest digest = new Digest(DigestAlgorithm.SHA256, digestBytes); String digestString = digest.toString(); Digest digestFromString = Digest.fromString(digestString); Assert.assertEquals(digestFromString, digest); }
@Test public final void testFromStringSHA384() { final byte[] digestBytes = getTestDigest(48); Digest digest = new Digest(DigestAlgorithm.SHA384, digestBytes); String digestString = digest.toString(); Digest digestFromString = Digest.fromString(digestString); Assert.assertEquals(digestFromString, digest); }
@Test public final void testFromStringSHA512() { final byte[] digestBytes = getTestDigest(64); Digest digest = new Digest(DigestAlgorithm.SHA512, digestBytes); String digestString = digest.toString(); Digest digestFromString = Digest.fromString(digestString); Assert.assertEquals(digestFromString, digest); }
@Test(expectedExceptions = IllegalArgumentException.class) public final void testFromStringInvalid() { String invalidDigestString = "SHA1 00000000000000000000"; Digest.fromString(invalidDigestString); }