@Test public void publish_whenCalledWithNull_shouldThrow() { thrown.expect(NullPointerException.class); enabledBus.publish(null); }
@Override public void publish(Event<?> event) { Preconditions.checkNotNull(event); synchronized (this) { if (pendingEvents != null) { pendingEvents.add(event); return; } } for (Map.Entry<EventHandler<Object>, Executor> handlerData : getHandlers(event)) { @SuppressWarnings("unchecked") Event<Object> casted = (Event<Object>) event; handlerData.getValue().execute(() -> handlerData.getKey().handle(casted)); } }
EventBus implements Subscriber, Publisher { @Override public void publish(Event<?> event) { Preconditions.checkNotNull(event); synchronized (this) { if (pendingEvents != null) { pendingEvents.add(event); return; } } for (Map.Entry<EventHandler<Object>, Executor> handlerData : getHandlers(event)) { @SuppressWarnings("unchecked") Event<Object> casted = (Event<Object>) event; handlerData.getValue().execute(() -> handlerData.getKey().handle(casted)); } } }
EventBus implements Subscriber, Publisher { @Override public void publish(Event<?> event) { Preconditions.checkNotNull(event); synchronized (this) { if (pendingEvents != null) { pendingEvents.add(event); return; } } for (Map.Entry<EventHandler<Object>, Executor> handlerData : getHandlers(event)) { @SuppressWarnings("unchecked") Event<Object> casted = (Event<Object>) event; handlerData.getValue().execute(() -> handlerData.getKey().handle(casted)); } } EventBus(Executor defaultExecutor); }
EventBus implements Subscriber, Publisher { @Override public void publish(Event<?> event) { Preconditions.checkNotNull(event); synchronized (this) { if (pendingEvents != null) { pendingEvents.add(event); return; } } for (Map.Entry<EventHandler<Object>, Executor> handlerData : getHandlers(event)) { @SuppressWarnings("unchecked") Event<Object> casted = (Event<Object>) event; handlerData.getValue().execute(() -> handlerData.getKey().handle(casted)); } } EventBus(Executor defaultExecutor); @Override void publish(Event<?> event); @Override synchronized void subscribe(
      Class<T> type, Executor executor, EventHandler<? super T> handler); @Override void subscribe(Class<T> type, EventHandler<? super T> handler); @Override synchronized void unsubscribe(Class<T> type, EventHandler<? super T> handler); }
EventBus implements Subscriber, Publisher { @Override public void publish(Event<?> event) { Preconditions.checkNotNull(event); synchronized (this) { if (pendingEvents != null) { pendingEvents.add(event); return; } } for (Map.Entry<EventHandler<Object>, Executor> handlerData : getHandlers(event)) { @SuppressWarnings("unchecked") Event<Object> casted = (Event<Object>) event; handlerData.getValue().execute(() -> handlerData.getKey().handle(casted)); } } EventBus(Executor defaultExecutor); @Override void publish(Event<?> event); @Override synchronized void subscribe(
      Class<T> type, Executor executor, EventHandler<? super T> handler); @Override void subscribe(Class<T> type, EventHandler<? super T> handler); @Override synchronized void unsubscribe(Class<T> type, EventHandler<? super T> handler);  }