### Question:
BcryptTool { static int execute(Arg arguments, PrintStream stream, PrintStream errorStream) { if (arguments == null) { return 2; } if (arguments.checkBcryptHash != null) { BCrypt.Result result = BCrypt.verifyer().verify(arguments.password, arguments.checkBcryptHash); if (!result.validFormat) { System.err.println("Invalid bcrypt format."); return 3; } if (result.verified) { stream.println("Hash verified."); } else { errorStream.println("Provided hash does not verify against given password."); return 1; } } else { byte[] salt = arguments.salt == null ? Bytes.random(16).array() : arguments.salt; byte[] hash = BCrypt.withDefaults().hash(arguments.costFactor, salt, charArrayToByteArray(arguments.password, StandardCharsets.UTF_8)); stream.println(new String(hash, StandardCharsets.UTF_8)); } return 0; } private  BcryptTool(); static void main(String[] args);  }### Answer:
@Test public void testNullArgument() { assertEquals(2, BcryptTool.execute(null, out, err)); }
@Test public void testExecuteHash() { int exitCode = BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -b 8 8e270d6129fd45f30a9b3fe44b4a8d9a")), out, err); verify(out).println("$2a$08$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G"); verify(err, never()).println(any(String.class)); assertEquals(0, exitCode); }
@Test public void testExecuteCheck() { int exitCode = BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -c '$2a$08$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G'")), out, err); verify(out).println(any(String.class)); verify(err, never()).println(any(String.class)); assertEquals(0, exitCode); }
@Test public void testCheckInvalidFormat() { assertEquals(3, BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -c '$2$$08$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G'")), out, err)); }
@Test public void testCheckDoesNotVerify() { assertEquals(1, BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -c '$2a$07$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G'")), out, err)); }