[jboss-cvs] JBossAS SVN: r108003 - in projects/ejb3/trunk/interceptors/src: test/java/org/jboss/ejb3/interceptors/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 7 05:38:47 EDT 2010
Author: jaikiran
Date: 2010-09-07 05:38:46 -0400 (Tue, 07 Sep 2010)
New Revision: 108003
Added:
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/Base.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/BeanA.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/unit/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/unit/ClassHelperTestCase.java
Modified:
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java
Log:
EJBTHREE-2165 Fix the isOverridden method in ClassHelper, which was returning true even for private methods
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java 2010-09-07 03:18:28 UTC (rev 108002)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java 2010-09-07 09:38:46 UTC (rev 108003)
@@ -289,13 +289,18 @@
* *in the passed collection of <code>methods</code>*. Returns true if the method
* is overriden by any of the passed methods, else returns false.
*
- * @param method
+ * @param method
* @param methods
* @return
*/
public static boolean isOverridden(Method method, Method... methods)
{
-
+ // if the method is "private" then it's not overridden
+ if(Modifier.isPrivate(method.getModifiers()))
+ {
+ return false;
+ }
+
for (Method someMethod : methods)
{
// first compare the names, if not equal then no
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/Base.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/Base.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/Base.java 2010-09-07 09:38:46 UTC (rev 108003)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.test.ejbthree2165;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * Base
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class Base
+{
+
+ private Object aroundInvoke(InvocationContext ctx)
+ {
+ return null;
+ }
+
+ public void someMethod()
+ {
+
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/BeanA.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/BeanA.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/BeanA.java 2010-09-07 09:38:46 UTC (rev 108003)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.test.ejbthree2165;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * BeanA
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class BeanA extends Base
+{
+
+ private Object aroundInvoke(InvocationContext ctx)
+ {
+ return null;
+ }
+
+ protected void doNothing()
+ {
+
+ }
+
+ @Override
+ public void someMethod()
+ {
+
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/unit/ClassHelperTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/unit/ClassHelperTestCase.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2165/unit/ClassHelperTestCase.java 2010-09-07 09:38:46 UTC (rev 108003)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.test.ejbthree2165.unit;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.interceptor.InvocationContext;
+
+import junit.framework.Assert;
+
+import org.jboss.ejb3.interceptors.lang.ClassHelper;
+import org.jboss.ejb3.interceptors.test.ejbthree2165.Base;
+import org.jboss.ejb3.interceptors.test.ejbthree2165.BeanA;
+import org.junit.Test;
+
+/**
+ * Tests for {@link ClassHelper}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ClassHelperTestCase
+{
+
+ /**
+ * Tests the {@link ClassHelper#isOverridden(Method, Method...)} method
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testIsMethodOverridden() throws Exception
+ {
+ Class<?> klass = BeanA.class;
+ List<Method> methods = new ArrayList<Method>();
+ // get all the methods on BeanA and its superclass
+ while (klass != null)
+ {
+ Method[] methodsOnClass = klass.getDeclaredMethods();
+ methods.addAll(Arrays.asList(methodsOnClass));
+
+ klass = klass.getSuperclass();
+ }
+ Method[] allMethods = methods.toArray(new Method[methods.size()]);
+
+ // private methods cannot be overridden
+ Method aroundInvokeOnBaseClass = Base.class.getDeclaredMethod("aroundInvoke", new Class<?>[] {InvocationContext.class});
+ // public method on base class which has been overridden in the sub-class
+ Method publicMethodOnBaseClass = Base.class.getDeclaredMethod("someMethod", new Class<?>[0]);
+ // protected method on sub-class (which isn't in base class)
+ Method protectedMethodOnBeanA = BeanA.class.getDeclaredMethod("doNothing", new Class<?>[0]);
+
+ // private method shouldn't be overridden
+ boolean isPrivateMethodOverridden = ClassHelper.isOverridden(aroundInvokeOnBaseClass, allMethods);
+ Assert.assertFalse("Private method was considered overridden", isPrivateMethodOverridden);
+
+ boolean isPublicMethodOverridden = ClassHelper.isOverridden(publicMethodOnBaseClass, allMethods);
+ Assert.assertTrue("Public method which was overridden in " + BeanA.class + " was *not* considered overridden", isPublicMethodOverridden);
+
+ boolean isProtectedMethodOverridden = ClassHelper.isOverridden(protectedMethodOnBeanA, allMethods);
+ Assert.assertFalse("Protected method which was *not* overridden in " + BeanA.class + " was considered overridden", isProtectedMethodOverridden);
+
+ // none of the methods on BeanA can be considered overridden, since
+ // BeanA doesn't have any sub-classes
+ for (Method methodOnBeanA : BeanA.class.getDeclaredMethods())
+ {
+ boolean isOverridden = ClassHelper.isOverridden(methodOnBeanA, allMethods);
+ Assert.assertFalse("Method: " + methodOnBeanA + " was incorrectly considered overridden", isOverridden);
+ }
+
+ }
+}
More information about the jboss-cvs-commits
mailing list