StreamingAeadUtil { public static String toHmacAlgo(HashType hash) throws NoSuchAlgorithmException { switch (hash) { case SHA1: return "HmacSha1"; case SHA256: return "HmacSha256"; case SHA512: return "HmacSha512"; default: throw new NoSuchAlgorithmException("hash unsupported for HMAC: " + hash); } }  static String toHmacAlgo(HashType hash);  }
@Test public void testToHmacAlgo() throws Exception { assertEquals("HmacSha1", StreamingAeadUtil.toHmacAlgo(HashType.SHA1)); assertEquals("HmacSha256", StreamingAeadUtil.toHmacAlgo(HashType.SHA256)); assertEquals("HmacSha512", StreamingAeadUtil.toHmacAlgo(HashType.SHA512)); try { StreamingAeadUtil.toHmacAlgo(HashType.UNKNOWN_HASH); fail("should throw NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException ex) { assertExceptionContains(ex, "hash unsupported for HMAC"); } }