You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/07/28 04:53:29 UTC

svn commit: r1151702 - in /myfaces/test/trunk/test20/src: main/java/org/apache/myfaces/test/mock/MockApplication20.java test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java

Author: lu4242
Date: Thu Jul 28 02:53:28 2011
New Revision: 1151702

URL: http://svn.apache.org/viewvc?rev=1151702&view=rev
Log:
MYFACESTEST-57 MockApplication20._createEvent does not deal with special constructors

Modified:
    myfaces/test/trunk/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
    myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java

Modified: myfaces/test/trunk/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java?rev=1151702&r1=1151701&r2=1151702&view=diff
==============================================================================
--- myfaces/test/trunk/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java (original)
+++ myfaces/test/trunk/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java Thu Jul 28 02:53:28 2011
@@ -510,15 +510,27 @@ public class MockApplication20 extends M
         {
             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);
             }
         }
 

Modified: myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java?rev=1151702&r1=1151701&r2=1151702&view=diff
==============================================================================
--- myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java (original)
+++ myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java Thu Jul 28 02:53:28 2011
@@ -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 @@ public class MockApplication20TestCase e
         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());
+    }
 }