openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1397919 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/events/observer/
Date Sat, 13 Oct 2012 18:26:35 GMT
Author: arne
Date: Sat Oct 13 18:26:35 2012
New Revision: 1397919

URL: http://svn.apache.org/viewvc?rev=1397919&view=rev
Log:
OWB-713 fixed overriding behavior for static methods

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/StaticTestEvent.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanA.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanB.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/EventTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Superclass.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=1397919&r1=1397918&r2=1397919&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
Sat Oct 13 18:26:35 2012
@@ -419,7 +419,7 @@ public final class AnnotationUtil
      */
     public static boolean isMethodOverridden(Method method, Collection<Method> overridingCandidates)
     {
-        if (overridingCandidates.isEmpty() || Modifier.isPrivate(method.getModifiers()))
+        if (overridingCandidates.isEmpty() || Modifier.isPrivate(method.getModifiers()) ||
Modifier.isStatic(method.getModifiers()))
         {
             return false;
         }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanA.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanA.java?rev=1397919&r1=1397918&r2=1397919&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanA.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanA.java
Sat Oct 13 18:26:35 2012
@@ -19,15 +19,16 @@
 package org.apache.webbeans.newtests.events.observer;
 
 
-import java.io.Serializable;
-
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
 
 @ApplicationScoped
-public class BeanA extends Superclass implements Serializable
+public class BeanA extends Superclass
 {
-    private static final long serialVersionUID = 821164664338581947L;
+
+    public static void observeTestEvent(@Observes StaticTestEvent testEvent) {
+        testEvent.addInvocation(BeanA.class.getSimpleName());
+    }
 
     private void observeTestEvent(@Observes PrivateTestEvent testEvent) {
         testEvent.addInvocation(getBeanName());

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanB.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanB.java?rev=1397919&r1=1397918&r2=1397919&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanB.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/BeanB.java
Sat Oct 13 18:26:35 2012
@@ -28,6 +28,10 @@ public class BeanB extends Superclass im
 {
     private static final long serialVersionUID = 821164664338581947L;
 
+    public static void observeTestEvent(StaticTestEvent testEvent) {
+        testEvent.addInvocation(BeanB.class.getSimpleName());
+    }
+
     private void observeTestEvent(PrivateTestEvent testEvent) {
         testEvent.addInvocation(getBeanName());
     }

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=1397919&r1=1397918&r2=1397919&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 Oct 13 18:26:35 2012
@@ -94,4 +94,39 @@ public class EventTest extends AbstractU
         shutDownContainer();
 
     }
+    
+    @Test
+    public void testObserverOnStaticMethod() {
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Superclass.class);
+        beanClasses.add(BeanA.class);
+        startContainer(beanClasses, null);
+
+        StaticTestEvent testEvent = new StaticTestEvent();
+        getBeanManager().fireEvent(testEvent);
+
+        Assert.assertEquals(2, testEvent.getCalledObservers().size());
+        Assert.assertTrue(testEvent.getCalledObservers().contains("BeanA"));
+        Assert.assertTrue(testEvent.getCalledObservers().contains("Superclass"));
+
+        shutDownContainer();
+
+    }
+    
+    @Test
+    public void testStaticMethodCannotBeOverridden() {
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Superclass.class);
+        beanClasses.add(BeanB.class);
+        startContainer(beanClasses, null);
+
+        StaticTestEvent testEvent = new StaticTestEvent();
+        getBeanManager().fireEvent(testEvent);
+
+        Assert.assertEquals(1, testEvent.getCalledObservers().size());
+        Assert.assertEquals("Superclass", testEvent.getCalledObservers().iterator().next());
+
+        shutDownContainer();
+
+    }
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/StaticTestEvent.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/StaticTestEvent.java?rev=1397919&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/StaticTestEvent.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/StaticTestEvent.java
Sat Oct 13 18:26:35 2012
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+public class StaticTestEvent
+{
+    private List<String> calledObserverNames = new ArrayList<String>();
+
+    public void addInvocation(String observerName)
+    {
+        this.calledObserverNames.add(observerName);
+    }
+
+    public List<String> getCalledObservers()
+    {
+        return calledObserverNames;
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Superclass.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Superclass.java?rev=1397919&r1=1397918&r2=1397919&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Superclass.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/events/observer/Superclass.java
Sat Oct 13 18:26:35 2012
@@ -23,6 +23,10 @@ import javax.enterprise.event.Observes;
 public abstract class Superclass
 {
 
+    public static void observeTestEvent(@Observes StaticTestEvent testEvent) {
+        testEvent.addInvocation(Superclass.class.getSimpleName());
+    }
+
     private void observeTestEvent(@Observes PrivateTestEvent testEvent) {
         testEvent.addInvocation(getBeanName() + "[" + Superclass.class.getSimpleName() +
"]");
     }



Mime
View raw message