WorkbenchBackendEntryPoint { @PostConstruct public void init() { bus.addLifecycleListener(new BusLifecycleAdapter() { @Override public void busOnline(final BusLifecycleEvent e) { logger.info("Bus is back online."); setShowedError(false); resetRetries(); } @Override public void busOffline(final BusLifecycleEvent e) { if (isShowedError()) { return; } logger.error("Bus is offline. [" + e.getReason().getErrorMessage() + "]"); if (!isWorkbenchOnCluster && !hasMoreRetries() && !isOpen()) { errorPopupPresenter.showMessage("You've been disconnected.", () -> isOpen = true, () -> isOpen = false); setShowedError(true); } decrementRetries(); } }); workbenchServices.isWorkbenchOnCluster(parameter -> isWorkbenchOnCluster = !(parameter == null || parameter.equals(Boolean.FALSE))); } WorkbenchBackendEntryPoint(); @Inject  WorkbenchBackendEntryPoint(final Logger logger,
                                      final ClientMessageBus bus,
                                      final WorkbenchServicesProxy workbenchServices,
                                      final ErrorPopupPresenter errorPopupPresenter); @PostConstruct void init();  }
@Test public void testNoErrorDisplay() { final WorkbenchBackendEntryPoint workbenchBackendEntryPoint = new WorkbenchBackendEntryPoint(logger, bus, workbenchServices, errorPopupPresenter); doAnswer((Answer<Void>) invocation -> { final Object[] args = invocation.getArguments(); final ParameterizedCommand<Boolean> obj = (ParameterizedCommand<Boolean>) args[0]; obj.execute(true); return null; }).when(workbenchServices).isWorkbenchOnCluster(any(ParameterizedCommand.class)); workbenchBackendEntryPoint.init(); final ArgumentCaptor<BusLifecycleListener> captor = ArgumentCaptor.forClass(BusLifecycleListener.class); verify(bus).addLifecycleListener(captor.capture()); final BusLifecycleListener listener = captor.getValue(); final TransportError error = mock(TransportError.class); final BusLifecycleEvent event = new BusLifecycleEvent(bus, error); listener.busOffline(event); verify(logger, times(1)).error((anyString())); verify(errorPopupPresenter, times(0)).showMessage(anyString()); listener.busOffline(event); verify(logger, times(2)).error((anyString())); verify(errorPopupPresenter, times(0)).showMessage(anyString()); listener.busOnline(event); verify(logger, times(1)).info((anyString())); verify(errorPopupPresenter, times(0)).showMessage(anyString()); listener.busOffline(event); listener.busOffline(event); verify(logger, times(4)).error((anyString())); verify(errorPopupPresenter, times(0)).showMessage(anyString()); }