MYFACESTEST-57 MockApplication20._createEvent does not deal with special constructors
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
index c2e1417..a9dd7ea 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
@@ -510,15 +510,27 @@
{
try
{
- Constructor<? extends SystemEvent> constructor = systemEventClass
- .getConstructor(Object.class);
- event = constructor.newInstance(source);
+ Constructor<?>[] constructors = systemEventClass.getConstructors();
+ Constructor<? extends SystemEvent> constructor = null;
+ for (Constructor<?> c : constructors)
+ {
+ if (c.getParameterTypes().length == 1)
+ {
+ // Safe cast, since the constructor belongs
+ // to a class of type SystemEvent
+ constructor = (Constructor<? extends SystemEvent>) c;
+ break;
+ }
+ }
+ if (constructor != null)
+ {
+ event = constructor.newInstance(source);
+ }
+
}
catch (Exception e)
{
- throw new FacesException(
- "Couldn't instanciate system event of type "
- + systemEventClass.getName(), e);
+ throw new FacesException("Couldn't instanciate system event of type " + systemEventClass.getName(), e);
}
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java b/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java
index ecd7b5d..7bf1ed1 100644
--- a/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java
@@ -17,12 +17,17 @@
package org.apache.myfaces.test.mock;
+import javax.faces.application.ProjectStage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.behavior.Behavior;
+import javax.faces.event.PostAddToViewEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.myfaces.test.base.AbstractJsfTestCase;
-import javax.faces.application.ProjectStage;
-import javax.faces.component.behavior.Behavior;
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
/**
* Test case for <code>MockApplication20</code>
@@ -91,4 +96,23 @@
assertTrue(_application.getDefaultValidatorInfo().containsKey(
validatorId));
}
+
+ public void testPublishEvent()
+ {
+ application.subscribeToEvent(PostAddToViewEvent.class, new SystemEventListener()
+ {
+
+ public void processEvent(SystemEvent event)
+ {
+
+ }
+
+ public boolean isListenerForSource(Object source)
+ {
+ return source instanceof UIViewRoot;
+ }
+ });
+
+ application.publishEvent(facesContext, PostAddToViewEvent.class, facesContext.getViewRoot());
+ }
}