HashUtil { public static byte[] hashSHA1(String str) { try { return hash("SHA1", str); } catch (NoSuchAlgorithmException e) { log.error("The algorithm is not available" + " in the caller's environment.", e); return null; } }  static byte[] hash(String algorithm, String str); static byte[] hashMD5(String str); static byte[] hashSHA1(String str);  }
@Test public void testHashSHA101() throws Exception { String paramStr = "abc"; byte[] resultHashValue = HashUtil.hashSHA1(paramStr); assertTrue( MessageDigest.isEqual( MessageDigest.getInstance("SHA1").digest("abc".getBytes()), resultHashValue)); }
@Test public void testHashSHA102() throws Exception { String paramStr = "あいう"; byte[] resultHashValue = HashUtil.hashSHA1(paramStr); assertTrue( MessageDigest.isEqual( MessageDigest.getInstance("SHA1").digest("あいう".getBytes()), resultHashValue)); }
@Test public void testHashSHA103() throws Exception { String paramStr = ""; byte[] resultHashValue = HashUtil.hashSHA1(paramStr); assertTrue( MessageDigest.isEqual( MessageDigest.getInstance("SHA1").digest("".getBytes()), resultHashValue)); }
@Test public void testHashSHA104() throws Exception { String paramStr = null; byte[] resultHashValue = HashUtil.hashSHA1(paramStr); assertNull(resultHashValue); }