jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1160997 - in /jackrabbit/commons/ocm/trunk/src: main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java test/java/org/apache/jackrabbit/ocm/reflection/ test/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtilsTest.java
Date Wed, 24 Aug 2011 07:52:52 GMT
Author: alexparvulescu
Date: Wed Aug 24 07:52:52 2011
New Revision: 1160997

URL: http://svn.apache.org/viewvc?rev=1160997&view=rev
Log:
OCM-45 ReflectionUtils.implementsInterface() only checks one interface and returns

Added:
    jackrabbit/commons/ocm/trunk/src/test/java/org/apache/jackrabbit/ocm/reflection/
    jackrabbit/commons/ocm/trunk/src/test/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtilsTest.java
  (with props)
Modified:
    jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java

Modified: jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java?rev=1160997&r1=1160996&r2=1160997&view=diff
==============================================================================
--- jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java
(original)
+++ jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java
Wed Aug 24 07:52:52 2011
@@ -208,31 +208,28 @@ abstract public class ReflectionUtils {
 
     /**
      * Check if an class is implementing an specific interface.
-     *
+     * 
      * @param clazz
      * @param interfaceClass
      * @return true if the class is implementing the interface otherwise false
      */
-	public static boolean implementsInterface( Class clazz, Class interfaceClass ) {
+    public static boolean implementsInterface(Class clazz, Class interfaceClass) {
 
-		// Try to find the interface class in the interfaces list
-		if (clazz.getInterfaces() != null  )
-		{
-		   for ( Class foundInterface : clazz.getInterfaces() ) {
-			   if ( foundInterface == interfaceClass ) {
-				  return true;
-			   }
-			   return implementsInterface(foundInterface, interfaceClass) ;
-		   }
-		}
-		// Try to find from the ancestors
-		if (clazz.getSuperclass() != null)
-		{
-		    return implementsInterface(clazz.getSuperclass(), interfaceClass);
-		}
-
-		return false;
-	}
+        // Try to find the interface class in the interfaces list
+        if (clazz.getInterfaces() != null) {
+            for (Class foundInterface : clazz.getInterfaces()) {
+                if (foundInterface == interfaceClass
+                        || implementsInterface(foundInterface, interfaceClass)) {
+                    return true;
+                }
+            }
+        }
+        // Try to find from the ancestors
+        if (clazz.getSuperclass() != null) {
+            return implementsInterface(clazz.getSuperclass(), interfaceClass);
+        }
+        return false;
+    }
 
 	/**
 	 * Get the default implementation for an interface

Added: jackrabbit/commons/ocm/trunk/src/test/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/ocm/trunk/src/test/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtilsTest.java?rev=1160997&view=auto
==============================================================================
--- jackrabbit/commons/ocm/trunk/src/test/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtilsTest.java
(added)
+++ jackrabbit/commons/ocm/trunk/src/test/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtilsTest.java
Wed Aug 24 07:52:52 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.jackrabbit.ocm.reflection;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class ReflectionUtilsTest extends TestCase {
+
+    public void testImplementsInterface() {
+        assertTrue(ReflectionUtils
+                .implementsInterface(HashMap.class, Map.class));
+        assertTrue(ReflectionUtils.implementsInterface(
+                Collections.EMPTY_MAP.getClass(), Map.class));
+    }
+
+}

Propchange: jackrabbit/commons/ocm/trunk/src/test/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtilsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message