### Question:
WorkspaceController { @EventListener public void saveWorkspace(SaveWorkspaceEvent event) { LOG.debug(DefaultI18nContext.getInstance().i18n("Requesting modules state")); CompletableFuture<Void> future = CompletableFuture .allOf(modules.stream() .map(m -> CompletableFuture.runAsync(() -> eventStudio().broadcast(event, m.id()))) .toArray(CompletableFuture[]::new)) .thenRun(() -> service.saveWorkspace(event.getData(), event.workspace())).whenComplete((r, e) -> { if (nonNull(e)) { LOG.error(DefaultI18nContext.getInstance().i18n("Unable to save modules workspace"), e); } }); if (event.awaitCompletion) { try { future.get(); } catch (InterruptedException | ExecutionException e) { LOG.error(DefaultI18nContext.getInstance().i18n("Unable to save workspace to {0}", event.workspace().getName()), e); } } } @Inject  WorkspaceController(List<Module> modules, WorkspaceService service, RecentWorkspacesService recentWorkspace); @EventListener void saveWorkspace(SaveWorkspaceEvent event); @EventListener CompletableFuture<Void> loadWorspace(LoadWorkspaceEvent event);  }### Answer:
@Test public void saveWorkspace() { Listener<SaveWorkspaceEvent> listener = mock(Listener.class); eventStudio().add(SaveWorkspaceEvent.class, listener, DefaultPriorityTestModule.ID); victim.saveWorkspace(new SaveWorkspaceEvent(file, true)); verify(listener).onEvent(any()); verify(service).saveWorkspace(anyMap(), eq(file)); }
@Test public void saveWorkspaceWithException() { Listener<SaveWorkspaceEvent> listener = mock(Listener.class); eventStudio().add(SaveWorkspaceEvent.class, listener, DefaultPriorityTestModule.ID); SaveWorkspaceEvent event = new SaveWorkspaceEvent(file, true); doThrow(new RuntimeException("mock")).when(listener).onEvent(event); victim.saveWorkspace(event); }