openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1426743 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/events/observer/ test/java/org/apache/webbeans/util/
Date Sat, 29 Dec 2012 10:49:45 GMT
Author: arne
Date: Sat Dec 29 10:49:45 2012
New Revision: 1426743

URL: http://svn.apache.org/viewvc?rev=1426743&view=rev
Log:
OWB-743: Fixed loop counter

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Green.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Orange.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Painter.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/EventTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1426743&r1=1426742&r2=1426743&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Sat Dec 29 10:49:45 2012
@@ -51,7 +51,6 @@ import java.util.logging.Logger;
  * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
  * @since 1.0
  */
-@SuppressWarnings("unchecked")
 public final class ClassUtil
 {
     public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
= new HashMap<Class<?>, Class<?>>();
@@ -1038,7 +1037,6 @@ public final class ClassUtil
 
         Method[] methods = SecurityUtil.doPrivilegedGetDeclaredMethods(clazz);
 
-        int j = 0;
         for (Method method : methods)
         {
             if (method.getName().equals(methodName))
@@ -1059,9 +1057,9 @@ public final class ClassUtil
 
                 if (!ok)
                 {
-                    for (Class<?> defineType : defineTypes)
+                    for (int i = 0; i < defineTypes.length; i++)
                     {
-                        if (defineType.isAssignableFrom(parameterTypes.get(j)))
+                        if (defineTypes[i].isAssignableFrom(parameterTypes.get(i)))
                         {
                             ok = true;
                         }
@@ -1069,8 +1067,6 @@ public final class ClassUtil
                         {
                             ok = false;
                         }
-
-                        j++;
                     }
                 }
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/EventTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/EventTest.java?rev=1426743&r1=1426742&r2=1426743&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/EventTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/EventTest.java
Sat Dec 29 10:49:45 2012
@@ -28,6 +28,27 @@ import org.junit.Test;
 public class EventTest extends AbstractUnitTest {
 
     @Test
+    public void multipleObserverMethodsWithSameName()
+    {
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Painter.class);
+        startContainer(beanClasses, null);
+
+        final Orange orange = new Orange();
+        getBeanManager().fireEvent(orange);
+
+        final Green green = new Green();
+        getBeanManager().fireEvent(green);
+
+        final Painter painter = getInstance(Painter.class);
+        Assert.assertEquals(2, painter.getObserved().size());
+        Assert.assertSame(orange, painter.getObserved().get(0));
+        Assert.assertSame(green, painter.getObserved().get(1));
+
+        shutDownContainer();
+    }
+
+    @Test
     public void testOverriddenObserverMethodsInSubclasses()
     {
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Green.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Green.java?rev=1426743&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Green.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Green.java
Sat Dec 29 10:49:45 2012
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.events.observer;
+
+public class Green {
+
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Orange.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Orange.java?rev=1426743&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Orange.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Orange.java
Sat Dec 29 10:49:45 2012
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.events.observer;
+
+public class Orange {
+
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Painter.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Painter.java?rev=1426743&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Painter.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Painter.java
Sat Dec 29 10:49:45 2012
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.events.observer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+
+@ApplicationScoped
+public class Painter {
+
+    private List<Object> observed = new ArrayList<Object>();
+
+    public void observe(@Observes Orange orange) {
+        observed.add(orange);
+    }
+
+    public void observe(@Observes Green green) {
+        observed.add(green);
+    }
+
+    public List<Object> getObserved() {
+        return observed;
+    }
+
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java?rev=1426743&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java
Sat Dec 29 10:49:45 2012
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.util;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.webbeans.newtests.events.observer.Green;
+import org.apache.webbeans.newtests.events.observer.Orange;
+import org.apache.webbeans.newtests.events.observer.Painter;
+import org.junit.Test;
+
+public class ClassUtilTest {
+
+    @Test
+    public void getClassMethodsWithTypes()
+    {
+        List<Method> orangeList = ClassUtil.getClassMethodsWithTypes(Painter.class,
"observe", Arrays.<Class<?>>asList(Orange.class));
+        Assert.assertEquals(1, orangeList.size());
+
+        List<Method> greenList = ClassUtil.getClassMethodsWithTypes(Painter.class,
"observe", Arrays.<Class<?>>asList(Green.class));
+        Assert.assertEquals(1, greenList.size());
+    }
+}



Mime
View raw message