Search in sources :

Example 6 with EventListenerReflectionRegistrator

use of com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator in project commons-gdx by gemserk.

the class EventListenerReflectionRegistratorTest method shouldRegisterEventListenerForMethodWithEventNameOnAnonymousClass.

@Test
public void shouldRegisterEventListenerForMethodWithEventNameOnAnonymousClass() {
    EventManagerImpl eventManager = new EventManagerImpl();
    anonymousWasCalled = false;
    Object myScript = new ScriptJavaImpl() {

        @SuppressWarnings("unused")
        public void customEvent(Event e) {
            anonymousWasCalled = true;
        }
    };
    EventListenerReflectionRegistrator eventListenerReflectionRegistrator = new EventListenerReflectionRegistrator(eventManager);
    eventListenerReflectionRegistrator.registerEventListener("customEvent", myScript);
    Event event = new Event();
    event.setId("customEvent");
    eventManager.process(event);
    assertThat(anonymousWasCalled, IsEqual.equalTo(true));
}
Also used : ScriptJavaImpl(com.gemserk.commons.artemis.scripts.ScriptJavaImpl) EventListenerReflectionRegistrator(com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator) Test(org.junit.Test)

Example 7 with EventListenerReflectionRegistrator

use of com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator in project commons-gdx by gemserk.

the class EventListenerReflectionRegistratorTest method shouldNotRegisterEventListenerIfNoMethodForEvent.

@Test
public void shouldNotRegisterEventListenerIfNoMethodForEvent() {
    EventManagerImpl eventManager = new EventManagerImpl();
    MyScript myScript = new MyScript();
    EventListenerReflectionRegistrator eventListenerReflectionRegistrator = new EventListenerReflectionRegistrator(eventManager);
    eventListenerReflectionRegistrator.registerEventListener("customEvent2", myScript);
    Event event = new Event();
    event.setId("customEvent");
    eventManager.process(event);
    assertThat(myScript.wasCalled, IsEqual.equalTo(false));
}
Also used : EventListenerReflectionRegistrator(com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator) Test(org.junit.Test)

Example 8 with EventListenerReflectionRegistrator

use of com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator in project commons-gdx by gemserk.

the class EventListenerReflectionRegistratorTest method bugArrayOutOfBoundsWhenRegisterOneIdsButMultipleMethodsWithHandes.

@Test
public void bugArrayOutOfBoundsWhenRegisterOneIdsButMultipleMethodsWithHandes() {
    EventManager eventManager = new EventManagerImpl();
    MyScript4 o = new MyScript4();
    EventListenerReflectionRegistrator eventListenerReflectionRegistrator = new EventListenerReflectionRegistrator(eventManager);
    eventListenerReflectionRegistrator.registerEventListeners(o);
}
Also used : EventListenerReflectionRegistrator(com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator) Test(org.junit.Test)

Example 9 with EventListenerReflectionRegistrator

use of com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator in project commons-gdx by gemserk.

the class EventListenerReflectionRegistratorTest method bugArrayOutOfBoundsWhenUnregisterOneIdsButMultipleMethodsWithHandes.

@Test
public void bugArrayOutOfBoundsWhenUnregisterOneIdsButMultipleMethodsWithHandes() {
    EventManager eventManager = new EventManagerImpl();
    MyScript4 o = new MyScript4();
    EventListenerReflectionRegistrator eventListenerReflectionRegistrator = new EventListenerReflectionRegistrator(eventManager);
    eventListenerReflectionRegistrator.registerEventListeners(o);
    eventListenerReflectionRegistrator.unregisterEventListeners(o);
}
Also used : EventListenerReflectionRegistrator(com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator) Test(org.junit.Test)

Aggregations

EventListenerReflectionRegistrator (com.gemserk.commons.artemis.events.reflection.EventListenerReflectionRegistrator)9 Test (org.junit.Test)9 ScriptJavaImpl (com.gemserk.commons.artemis.scripts.ScriptJavaImpl)1