ComponentEventBus implements Serializable { @SuppressWarnings({ "unchecked", "rawtypes" }) public void fireEvent(ComponentEvent event) { Class<? extends ComponentEvent> eventType = event.getClass(); if (!hasListener(eventType)) { return; } for (ListenerWrapper wrapper : new ArrayList<>( componentEventData.get(event.getClass()))) { fireEventForListener(event, wrapper); } } ComponentEventBus(Component component); Registration addListener(
            Class<T> eventType, ComponentEventListener<T> listener); Registration addListener(
            Class<T> eventType, ComponentEventListener<T> listener,
            Consumer<DomListenerRegistration> domListenerConsumer); @SuppressWarnings("rawtypes") boolean hasListener(Class<? extends ComponentEvent> eventType); @SuppressWarnings({ "unchecked", "rawtypes" }) void fireEvent(ComponentEvent event);  }
@Test public void serverEvent_fire() { AtomicInteger eventHandlerCalled = new AtomicInteger(0); AtomicReference<BigDecimal> dataValueInEvent = new AtomicReference<>( new BigDecimal(0)); TestComponentWithServerEvent component = new TestComponentWithServerEvent(); component.addServerEventListener(e -> { eventHandlerCalled.incrementAndGet(); dataValueInEvent.set(e.getSomeValue()); }); component .fireEvent(new ServerEvent(component, new BigDecimal("12.22"))); Assert.assertEquals(1, eventHandlerCalled.get()); Assert.assertEquals(new BigDecimal("12.22"), dataValueInEvent.get()); }
@Test public void serverNoDataEvent_fire_noListeners() { TestComponent c = new TestComponent(); c.fireEvent(new ServerNoDataEvent(c, false)); }
@Test public void testFireEvent_noListeners_eventBusNotCreated() { AtomicInteger eventBusCreated = new AtomicInteger(); TestComponent c = new TestComponent() { @Override public ComponentEventBus getEventBus() { eventBusCreated.incrementAndGet(); return super.getEventBus(); } }; c.fireEvent(new ServerEvent(c, new BigDecimal(0))); Assert.assertEquals(0, eventBusCreated.get()); }