### Question:
EncryptionUtil { public static HashingAlgorithm getHashingAlgorithm(String password) { if (password.startsWith("$2y")) { if (getBCryptCost(password) < BCRYPT_MIN_COST) { throw new HashedPasswordException("Minimum cost of BCrypt password must be " + BCRYPT_MIN_COST); } return HashingAlgorithm.BCRYPT; } if (password.contains(":")) { if (getPBKDF2Iterations(password) < PBKDF2_MIN_ITERATIONS) { throw new HashedPasswordException("Minimum iterations of PBKDF2 password must be " + PBKDF2_MIN_ITERATIONS); } return HashingAlgorithm.PBKDF2; } throw new HashedPasswordException("Password hashing algorithm cannot be determined"); } private  EncryptionUtil(); static int getBCryptCost(String password); static int getPBKDF2Iterations(String password); static boolean doesBCryptPasswordMatch(String inputPassword, String hashedPassword); static boolean doesPBKDF2PasswordMatch(String inputPassword, String hashedPassword); static HashingAlgorithm getHashingAlgorithm(String password);  }### Answer:
@Test public void testHashingAlgorithmBCrypt() { String password = "$2y$10$BqTb8hScP5DfcpmHo5PeyugxHz5Ky/qf3wrpD7SNm8sWuA3VlGqsa"; assertEquals(getHashingAlgorithm(password), BCRYPT); }
@Test public void testHashingAlgorithmPBKDF2() { String password = "1000:5b4240333032306164:f38d165fce8ce42f59d366139ef5d9e1ca1247f0e06e503ee1a611dd9ec40876bb5edb8409f5abe5504aab6628e70cfb3d3a18e99d70357d295002c3d0a308a0"; assertEquals(getHashingAlgorithm(password), PBKDF2); }
@Test public void testMinBCryptCost() { String password = "$2y$07$XxMSjoWesbX9s9LCD5Kp1OaFD/bcLUq0zoRCTsTNwjF6N/nwHVCVm"; assertThatThrownBy(() -> getHashingAlgorithm(password)) .isInstanceOf(HashedPasswordException.class) .hasMessage("Minimum cost of BCrypt password must be 8"); }
@Test public void testInvalidPasswordFormatPBKDF2() { String password = "100:5b4240333032306164:f38d165fce8ce42f59d366139ef5d9e1ca1247f0e06e503ee1a611dd9ec40876bb5edb8409f5abe5504aab6628e70cfb3d3a18e99d70357d295002c3d0a308a0"; assertThatThrownBy(() -> getHashingAlgorithm(password)) .isInstanceOf(HashedPasswordException.class) .hasMessage("Minimum iterations of PBKDF2 password must be 1000"); }