EventBus { public static void register(Class<? extends Event> eventClass, Subscriber subscriber) { CopyOnWriteArraySet<Subscriber> set = SUBSCRIBER_MAP.get(eventClass); if (set == null) { set = new CopyOnWriteArraySet<Subscriber>(); CopyOnWriteArraySet<Subscriber> old = SUBSCRIBER_MAP.putIfAbsent(eventClass, set); if (old != null) { set = old; } } set.add(subscriber); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Register subscriber: {} of event: {}.", subscriber, eventClass); } }  static boolean isEnable(); static boolean isEnable(Class<? extends Event> eventClass); static void register(Class<? extends Event> eventClass, Subscriber subscriber); static void unRegister(Class<? extends Event> eventClass, Subscriber subscriber); static void post(final Event event);  }
@Test public void register() throws Exception { Subscriber subscriber = new TestSubscriber(); try { Assert.assertEquals(EventBus.isEnable(TestEvent.class), false); EventBus.register(TestEvent.class, subscriber); Assert.assertEquals(EventBus.isEnable(TestEvent.class), true); } finally { EventBus.unRegister(TestEvent.class, subscriber); } Assert.assertEquals(EventBus.isEnable(TestEvent.class), false); }