### Question:
WorkArea extends BorderPane { @EventListener public void onSetActiveModule(SetActiveModuleRequest request) { request.getActiveModuleId().ifPresent(id -> { Module requested = modules.get(id); if (requested != null) { current = Optional.of(requested); center.setContent(requested.modulePanel()); fade.play(); } }); eventStudio().broadcast(new SetTitleEvent(current.map(m -> m.descriptor().getName()).orElse(""))); } @Inject  WorkArea(List<Module> modules, QuickbarModuleButtonsPane modulesButtons); @EventListener void onSetActiveModule(SetActiveModuleRequest request);  }### Answer:
@Test public void wrongModuleDoesntBoom() { WorkArea victim = injector.instance(WorkArea.class); victim.onSetActiveModule(SetActiveModuleRequest.activeteModule("chuck norris")); }
@Test public void eventTitleIsSent() { WorkArea victim = injector.instance(WorkArea.class); assertNull(((ScrollPane) victim.getCenter()).getContent()); Listener<SetTitleEvent> listener = mock(Listener.class); eventStudio().add(SetTitleEvent.class, listener); victim.onSetActiveModule(SetActiveModuleRequest.activeteModule(DefaultPriorityTestModule.ID)); ArgumentCaptor<SetTitleEvent> captor = ArgumentCaptor.forClass(SetTitleEvent.class); verify(listener).onEvent(captor.capture()); assertEquals(injector.instance(TestModule.class).descriptor().getName(), captor.getValue().getTitle()); assertNotNull(((ScrollPane) victim.getCenter()).getContent()); }
@Test public void emptyEventTitleIsSent() { WorkArea victim = injector.instance(WorkArea.class); Listener<SetTitleEvent> listener = mock(Listener.class); eventStudio().add(SetTitleEvent.class, listener); victim.onSetActiveModule(SetActiveModuleRequest.activeteCurrentModule()); ArgumentCaptor<SetTitleEvent> captor = ArgumentCaptor.forClass(SetTitleEvent.class); verify(listener).onEvent(captor.capture()); assertTrue(isBlank(captor.getValue().getTitle())); }
@Test public void previousEventTitleIsSent() { WorkArea victim = injector.instance(WorkArea.class); victim.onSetActiveModule(SetActiveModuleRequest.activeteModule(DefaultPriorityTestModule.ID)); eventStudio().clear(); Listener<SetTitleEvent> listener = mock(Listener.class); eventStudio().add(SetTitleEvent.class, listener); victim.onSetActiveModule(SetActiveModuleRequest.activeteCurrentModule()); ArgumentCaptor<SetTitleEvent> captor = ArgumentCaptor.forClass(SetTitleEvent.class); verify(listener).onEvent(captor.capture()); assertEquals(injector.instance(TestModule.class).descriptor().getName(), captor.getValue().getTitle()); }