EventUtils { public static boolean shouldHandleEvent(final IMessageProcessingEventConfiguration handlerCfg, final IMessageProcessingEvent event) { boolean shouldHandle = true; final IMessageUnit subject = event.getSubject(); final List<Class<? extends IMessageProcessingEvent>> handledEvents = handlerCfg.getHandledEvents(); final List<Class<? extends IMessageUnit>> forMsgUnits = handlerCfg.appliesTo(); if (!Utils.isNullOrEmpty(handledEvents)) { boolean appliesTo = false; for (final Class<?> cls : handledEvents) appliesTo |= cls.isAssignableFrom(event.getClass()); shouldHandle &= appliesTo; } if (!Utils.isNullOrEmpty(forMsgUnits)) { boolean appliesTo = false; for (final Class<?> cls : forMsgUnits) appliesTo |= cls.isAssignableFrom(subject.getClass()); shouldHandle &= appliesTo; } return shouldHandle; }  static boolean shouldHandleEvent(final IMessageProcessingEventConfiguration handlerCfg,
                                            final IMessageProcessingEvent event);  }
@Test public void testShouldHandleEvent() throws Exception { EventForTest event = new EventForTest(null); AnotherEventForTest unhandledEvent = new AnotherEventForTest(null); EventHandlerConfig config = new EventHandlerConfig(); List<Class<? extends IMessageProcessingEvent>> list = new ArrayList<>(); list.add(event.getClass()); config.setHandledEvents(list); assertTrue(EventUtils.shouldHandleEvent(config, event)); assertFalse(EventUtils.shouldHandleEvent(config, unhandledEvent)); }