@Test void createMessageDigest_test_with_wrong_arg() { assertThrows(IllegalArgumentException.class, () -> MessageDigestUtil.createMessageDigest("wrong-arg") ); }
public static MessageDigest createMessageDigest(String hashAlgorithm) { try { switch (hashAlgorithm) { case "S256": return MessageDigest.getInstance("SHA-256"); case "S384": return MessageDigest.getInstance("SHA-384"); case "S512": return MessageDigest.getInstance("SHA-512"); default: return MessageDigest.getInstance(hashAlgorithm); } } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } }
MessageDigestUtil { public static MessageDigest createMessageDigest(String hashAlgorithm) { try { switch (hashAlgorithm) { case "S256": return MessageDigest.getInstance("SHA-256"); case "S384": return MessageDigest.getInstance("SHA-384"); case "S512": return MessageDigest.getInstance("SHA-512"); default: return MessageDigest.getInstance(hashAlgorithm); } } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } } }
MessageDigestUtil { public static MessageDigest createMessageDigest(String hashAlgorithm) { try { switch (hashAlgorithm) { case "S256": return MessageDigest.getInstance("SHA-256"); case "S384": return MessageDigest.getInstance("SHA-384"); case "S512": return MessageDigest.getInstance("SHA-512"); default: return MessageDigest.getInstance(hashAlgorithm); } } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } } private  MessageDigestUtil(); }
MessageDigestUtil { public static MessageDigest createMessageDigest(String hashAlgorithm) { try { switch (hashAlgorithm) { case "S256": return MessageDigest.getInstance("SHA-256"); case "S384": return MessageDigest.getInstance("SHA-384"); case "S512": return MessageDigest.getInstance("SHA-512"); default: return MessageDigest.getInstance(hashAlgorithm); } } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } } private  MessageDigestUtil(); static MessageDigest createMessageDigest(String hashAlgorithm); static MessageDigest createSHA256(); }
MessageDigestUtil { public static MessageDigest createMessageDigest(String hashAlgorithm) { try { switch (hashAlgorithm) { case "S256": return MessageDigest.getInstance("SHA-256"); case "S384": return MessageDigest.getInstance("SHA-384"); case "S512": return MessageDigest.getInstance("SHA-512"); default: return MessageDigest.getInstance(hashAlgorithm); } } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } } private  MessageDigestUtil(); static MessageDigest createMessageDigest(String hashAlgorithm); static MessageDigest createSHA256();  }