Multicaster support for events with null source

Update `AbstractApplicationEventMulticaster` to support `EventObjects`
with a null source (which can happen if they have been serialized).

Issue: SPR-10945
This commit is contained in:
Phillip Webb
2013-10-21 11:55:16 -07:00
parent 6d882b149d
commit b0ff834ee3
5 changed files with 45 additions and 31 deletions

View File

@@ -96,18 +96,11 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
* @see org.springframework.context.AbstractApplicationContextTests#testEvents()
*/
@Override
public void testEvents() throws Exception {
TestListener listener = (TestListener) this.applicationContext.getBean("testListener");
listener.zeroCounter();
TestListener parentListener = (TestListener) this.applicationContext.getParent().getBean("parentListener");
parentListener.zeroCounter();
parentListener.zeroCounter();
assertTrue("0 events before publication", listener.getEventCount() == 0);
assertTrue("0 parent events before publication", parentListener.getEventCount() == 0);
this.applicationContext.publishEvent(new MyEvent(this));
assertTrue("1 events after publication, not " + listener.getEventCount(), listener.getEventCount() == 1);
assertTrue("1 parent events after publication", parentListener.getEventCount() == 1);
protected void doTestEvents(TestListener listener, TestListener parentListener,
MyEvent event) {
TestListener listenerBean = (TestListener) this.applicationContext.getBean("testListener");
TestListener parentListenerBean = (TestListener) this.applicationContext.getParent().getBean("parentListener");
super.doTestEvents(listenerBean, parentListenerBean, event);
}
@Override