@Test public void shouldBeAbleToReadAndInvokeObserverMethods() throws Exception { ExtensionWithObservers target = new ExtensionWithObservers(); Extension extension = ExtensionImpl.of(target); Assert.assertEquals( "Verify correct observer methods were found", 2, extension.getObservers().size()); for (ObserverMethod observer : extension.getObservers()) { observer.invoke(null, new String()); } Assert.assertTrue(target.methodOneWasCalled); Assert.assertTrue(target.methodTwoWasCalled); }
@Test public void shouldBeAbleToReadAndInvokeInjectionPoints() throws Exception { ExtensionWithInjection target = new ExtensionWithInjection(); Extension extension = ExtensionImpl.of(target); Assert.assertEquals( "Verify correct injection fields were found", 1, extension.getInjectionPoints().size()); Instance<Object> instance = new DummyInstanceImpl(); for (InjectionPoint point : extension.getInjectionPoints()) { point.set(instance); } extension.getObservers().get(0).invoke(null, new Object()); Assert.assertTrue(target.methodOneWasCalled); Assert.assertNotNull(instance.get()); }
@Test public void shouldBeAbleToInjectEventAndFireNewEvent() throws Exception { ExtensionWithEvent target = new ExtensionWithEvent(); Extension extension = ExtensionImpl.of(target); Assert.assertEquals( "Verify correct event fields were found", 1, extension.getEventPoints().size()); Assert.assertEquals(1, extension.getObservers().size()); DummyEventImpl event = new DummyEventImpl(); for (EventPoint point : extension.getEventPoints()) { point.set(event); } extension.getObservers().get(0).invoke(null, new Object()); Assert.assertTrue(target.methodOneWasCalled); Assert.assertEquals( "Verify the Extensions Event was firable", "some string", event.getString()); }