CommandLine implements Callable<Optional<Function<Lifecycle, InvestmentMode>>> { public static Optional<Function<Lifecycle, InvestmentMode>> parse(final App main) { final CommandLine cli = new CommandLine(); final picocli.CommandLine pico = new picocli.CommandLine(cli); pico.execute(main.getArgs()); final Optional<Function<Lifecycle, InvestmentMode>> result = pico.getExecutionResult(); return Objects.isNull(result) ? Optional.empty() : result; } CommandLine(); static Optional<Function<Lifecycle, InvestmentMode>> parse(final App main); @Override Optional<Function<Lifecycle, InvestmentMode>> call();  }
@Test void validDaemonCli() throws IOException, KeyStoreException { final String keyStorePassword = "password"; final File keystore = File.createTempFile("robozonky-", ".keystore"); keystore.delete(); final KeyStoreHandler ksh = KeyStoreHandler.create(keystore, keyStorePassword.toCharArray()); SecretProvider.keyStoreBased(ksh, USERNAME, "something".toCharArray()); final String name = UUID.randomUUID() .toString(); final App main = new App("-n", name, "-g", keystore.getAbsolutePath(), "-p", keyStorePassword, "-i", "somewhere.txt", "-s", "somewhere"); final Optional<Function<Lifecycle, InvestmentMode>> cfg = CommandLine.parse(main); assertThat(cfg).isPresent(); assertThat(cfg.get() .apply(null)).isInstanceOf(Daemon.class); assertThat(ListenerServiceLoader.getNotificationConfiguration(mockSessionInfo())).isNotEmpty(); }
@Test void validDaemonCliNoKeystore() { final App main = mockedApp("-g", "a", "-p", "p", "-i", "somewhere.txt", "-s", "somewhere"); final Optional<Function<Lifecycle, InvestmentMode>> cfg = CommandLine.parse(main); assertThat(cfg).isEmpty(); }