### Question:
EntityEventDispatcher { public void fireEventListeners(EntityMetadata metadata, Object entity, Class<?> event) { List<? extends CallbackMethod> callBackMethods = metadata.getCallbackMethods(event); if (null != callBackMethods && !callBackMethods.isEmpty() && null != entity) { log.debug("Callback >> " + event.getSimpleName() + " on " + metadata.getEntityClazz().getName()); for (CallbackMethod callback : callBackMethods) { log.debug("Firing >> " + callback); callback.invoke(entity); } } }  void fireEventListeners(EntityMetadata metadata, Object entity, Class<?> event);  }### Answer:
@Test public void testExternalFireEventListeners() throws NoSuchMethodException, SecurityException { PersonEventDispatch person = new PersonEventDispatch("1", "John", "Smith"); EntityMetadata m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, person.getClass()); eventDispatcher.fireEventListeners(m, person, PrePersist.class); Assert.assertEquals("Amresh", person.getFirstName()); Assert.assertEquals("Smith", person.getLastName()); eventDispatcher.fireEventListeners(m, person, PostPersist.class); Assert.assertEquals("Amresh", person.getFirstName()); Assert.assertEquals("Singh", person.getLastName()); eventDispatcher.fireEventListeners(m, person, PostLoad.class); eventDispatcher.fireEventListeners(m, null, PostLoad.class); Assert.assertEquals("Amresh", person.getFirstName()); Assert.assertEquals("Post Load", person.getLastName()); try { ExternalCallbackMethod callback = new ExternalCallbackMethod(PersonEventDispatch.class, PersonEventDispatch.class.getDeclaredMethod("getFirstName", null)); AddressEntity address = new AddressEntity(); address.setAddressId("addr1"); address.setStreet("street"); address.setCity("noida"); callback.invoke(address); Assert.fail("Should have gone to catch block!"); } catch (EventListenerException elex) { Assert.assertNotNull(elex); } }
@Test public void testInternalFireEventListeners() throws NoSuchMethodException, SecurityException { AddressEntity address = new AddressEntity(); address.setAddressId("addr1"); address.setStreet("street"); address.setCity("noida"); EntityMetadata m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, address.getClass()); eventDispatcher.fireEventListeners(m, address, PrePersist.class); eventDispatcher.fireEventListeners(m, null, PrePersist.class); Assert.assertEquals("addr1", address.getAddressId()); Assert.assertEquals("noida", address.getCity()); Assert.assertEquals("street,noida", address.getFullAddress()); try { InternalCallbackMethod callback = new InternalCallbackMethod(m, AddressEntity.class.getDeclaredMethod( "getStreet", null)); PersonEventDispatch person = new PersonEventDispatch("1", "John", "Smith"); callback.invoke(person); Assert.fail("Should have gone to catch block!"); } catch (EventListenerException elex) { Assert.assertNotNull(elex); } }