RoboZonkyStartupNotifier implements ShutdownHook.Handler { @Override public Optional<Consumer<ReturnCode>> get() { var version = Defaults.ROBOZONKY_VERSION; LOGGER.info(readBanner(version)); LOGGER.debug("Running {} {} v{} from {}.", getProperty("java.vm.vendor"), getProperty("java.vm.name"), getProperty("java.vm.version"), getProperty("java.home")); LOGGER.debug("Running on {} v{} ({}, {} CPUs, {}, {}).", getProperty("os.name"), getProperty("os.version"), getProperty("os.arch"), getRuntime().availableProcessors(), Locale.getDefault(), Charset.defaultCharset()); LOGGER.debug("Current working directory is '{}'.", getProperty("user.dir")); if (session.isDryRun()) { LOGGER.info("RoboZonky is doing a dry run. It will not invest any real money."); } Events.global() .fire(roboZonkyInitialized()); return Optional.of(result -> { final CompletableFuture<?> waitUntilFired = Events.global() .fire(roboZonkyEnding()); try { LOGGER.debug("Waiting for events to be processed."); waitUntilFired.join(); } catch (final Exception ex) { LOGGER.debug("Exception while waiting for the final event being processed.", ex); } finally { LOGGER.info("RoboZonky v{} '{}' out.", version, session.getName()); } }); } RoboZonkyStartupNotifier(final SessionInfo session); @Override Optional<Consumer<ReturnCode>> get();  }
@Test void properEventsFired() { final RoboZonkyStartupNotifier rzsn = new RoboZonkyStartupNotifier(SESSION); final Optional<Consumer<ReturnCode>> result = rzsn.get(); assertThat(result).isPresent(); assertThat(this.getEventsRequested()).last() .isInstanceOf(RoboZonkyInitializedEvent.class); final ReturnCode r = ReturnCode.OK; result.get() .accept(r); assertThat(this.getEventsRequested()).last() .isInstanceOf(RoboZonkyEndingEvent.class); }