### Question:
EventListener implements Comparable<EventListener> { public void handle(Event event) { if (event == null) throw new NullPointerException("Event required."); if (skipCancelledEvents) { if ( ClassReflection.isInstance(Cancellable.class, event) && ((Cancellable)event).isCancelled() ) { return; } } try { method.invoke(object, event); } catch (Exception e) { throw new RuntimeException("Could not call event.", e); } } EventListener(Object object, Method method);  EventListener(Object object, Method method, int priority, boolean skipCancelledEvents); void handle(Event event); Object getObject(); Method getMethod(); Class getParameterType(); int getPriority(); boolean isSkipCancelledEvents(); @Override int compareTo(EventListener o);  }### Answer:
@Test public void CancelledEvent_ListenerIgnoringCancelled_IgnoresCancelled() throws ReflectionException { class ListenerPojo { public void neverCall(CancellableEvent event) { Assert.fail(); } } ListenerPojo pojo = new ListenerPojo(); new EventListener(pojo, findMethod(pojo, "neverCall", CancellableEvent.class),0,true).handle(new CancellableEvent(true)); }
@Test public void CancelledEvent_ListenerAcceptingCancelled_AcceptsCancelled() throws ReflectionException { class ListenerPojo { int count=0; public void call(CancellableEvent event) { count++; } } ListenerPojo pojo = new ListenerPojo(); new EventListener(pojo, findMethod(pojo, "call", CancellableEvent.class),0,false).handle(new CancellableEvent(true)); Assert.assertEquals(1, pojo.count); }
@Test public void NotCancelledEvent_ListenerIgnoringCancelled_AcceptsNotCancelled() throws ReflectionException { class ListenerPojo { int count=0; public void call(CancellableEvent event) { count++; } } ListenerPojo pojo = new ListenerPojo(); new EventListener(pojo, findMethod(pojo, "call", CancellableEvent.class),0,true).handle(new CancellableEvent(false)); Assert.assertEquals(1, pojo.count); }
@Test public void NotCancelledEvent_ListenerAcceptingCancelled_AcceptsNotCancelled() throws ReflectionException { class ListenerPojo { int count=0; public void call(CancellableEvent event) { count++; } } ListenerPojo pojo = new ListenerPojo(); new EventListener(pojo, findMethod(pojo, "call", CancellableEvent.class),0,false).handle(new CancellableEvent(false)); Assert.assertEquals(1, pojo.count); }