### Question:
KeyUpdateCommand implements Callable<CliResult> { List<char[]> passwords() throws IOException { if (password != null) { return singletonList(password.toCharArray()); } else if (passwordFile != null) { return Files.readAllLines(passwordFile).stream().map(String::toCharArray).collect(Collectors.toList()); } else { return emptyList(); } } KeyUpdateCommand(KeyEncryptorFactory keyEncryptorFactory, PasswordReader passwordReader); @Override CliResult call(); CliResult execute(); @CommandLine.Option(names = "--keys.keyData.privateKeyPath", required = true)
    public Path privateKeyPath; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.algorithm", defaultValue = "i")
    public String algorithm; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.iterations", defaultValue = "10")
    public Integer iterations; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.memory", defaultValue = "1048576")
    public Integer memory; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.parallelism", defaultValue = "4")
    public Integer parallelism; @CommandLine.Option(names = {"--keys.passwords"})
    public String password; @CommandLine.Option(names = {"--keys.passwordFile"})
    public Path passwordFile; @CommandLine.Option(
            names = {"--configfile", "-configfile"},
            description = "Path to node configuration file")
    public Config config; @CommandLine.Mixin public EncryptorOptions encryptorOptions; @CommandLine.Mixin public DebugOptions debugOptions; }### Answer:
@Test public void inlinePasswordParsed() throws IOException { command.password = "pass"; final List<char[]> passwords = command.passwords(); assertThat(passwords).isNotNull().hasSize(1).containsExactly("pass".toCharArray()); }
@Test public void passwordFileParsedAndRead() throws IOException { final Path passwordFile = Files.createTempFile("passwords", ".txt"); Files.write(passwordFile, "passwordInsideFile\nsecondPassword".getBytes()); command.passwordFile = passwordFile; final List<char[]> passwords = command.passwords(); assertThat(passwords) .isNotNull() .hasSize(2) .containsExactly("passwordInsideFile".toCharArray(), "secondPassword".toCharArray()); }
@Test public void passwordFileThrowsErrorIfCantBeRead() { command.passwordFile = Paths.get("/tmp/passwords.txt"); final Throwable throwable = catchThrowable(() -> command.passwords()); assertThat(throwable).isNotNull().isInstanceOf(IOException.class); }
@Test public void emptyListGivenForNoPasswords() throws IOException { final List<char[]> passwords = command.passwords(); assertThat(passwords).isNotNull().isEmpty(); }