### Question:
UpdatesController { @EventListener public void checkForUpdates(UpdateCheckRequest event) { LOG.debug(DefaultI18nContext.getInstance().i18n("Checking for updates")); CompletableFuture.supplyAsync(service::getLatestVersion).thenAccept(current -> { if (isNotBlank(current)) { if (!pdfsam.property(VERSION).equals(current)) { LOG.info(DefaultI18nContext.getInstance().i18n("PDFsam {0} is available for download", current)); eventStudio().broadcast(new UpdateAvailableEvent(current)); } else if (event.nofityNoUpdates) { eventStudio().broadcast(new NoUpdateAvailable()); } } }).whenComplete((r, e) -> { if (nonNull(e)) { LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to find the latest available version."), e); } }); } @Inject  UpdatesController(UpdateService service, Pdfsam pdfsam); @EventListener void checkForUpdates(UpdateCheckRequest event);  }### Answer:
@Test public void pasitiveCheckForUpdates() { when(service.getLatestVersion()).thenReturn("3.0.0"); eventStudio().add(UpdateAvailableEvent.class, listener); victim.checkForUpdates(UpdateCheckRequest.INSTANCE); verify(service, timeout(1000).times(1)).getLatestVersion(); verify(listener, timeout(1000).times(1)).onEvent(any(UpdateAvailableEvent.class)); }
@Test public void pasitiveCheckForUpdatesNotifyNoUpdates() { when(service.getLatestVersion()).thenReturn("3.0.0"); eventStudio().add(UpdateAvailableEvent.class, listener); eventStudio().add(NoUpdateAvailable.class, noUpdatesListener); victim.checkForUpdates(new UpdateCheckRequest(true)); verify(service, timeout(1000).times(1)).getLatestVersion(); verify(listener, timeout(1000).times(1)).onEvent(any(UpdateAvailableEvent.class)); verify(noUpdatesListener, after(1000).never()).onEvent(any(NoUpdateAvailable.class)); }
@Test public void negativeCheckForUpdates() { when(service.getLatestVersion()).thenReturn("3.0.0.M1"); eventStudio().add(UpdateAvailableEvent.class, listener); victim.checkForUpdates(UpdateCheckRequest.INSTANCE); verify(service, timeout(1000).times(1)).getLatestVersion(); verify(listener, after(1000).never()).onEvent(any(UpdateAvailableEvent.class)); }
@Test public void negativeCheckForUpdatesNotifyNoUpdates() { when(service.getLatestVersion()).thenReturn("3.0.0.M1"); eventStudio().add(UpdateAvailableEvent.class, listener); eventStudio().add(NoUpdateAvailable.class, noUpdatesListener); victim.checkForUpdates(new UpdateCheckRequest(true)); verify(service, timeout(1000).times(1)).getLatestVersion(); verify(listener, after(1000).never()).onEvent(any(UpdateAvailableEvent.class)); verify(noUpdatesListener, timeout(1000).times(1)).onEvent(any(NoUpdateAvailable.class)); }
@Test public void exceptionalCheckForUpdates() { when(service.getLatestVersion()).thenThrow(new RuntimeException("Mock")); eventStudio().add(UpdateAvailableEvent.class, listener); victim.checkForUpdates(UpdateCheckRequest.INSTANCE); verify(service, timeout(1000).times(1)).getLatestVersion(); verify(listener, after(1000).never()).onEvent(any(UpdateAvailableEvent.class)); }