From ab3929dcce48b2a59a4493acf4d804ad99e58821 Mon Sep 17 00:00:00 2001
From: ribeaudc <ribeaudc>
Date: Fri, 7 Mar 2008 09:42:52 +0000
Subject: [PATCH] fix: - Given 'annotationClass' not considered.

SVN: 4670
---
 .../cisd/common/utilities/ClassUtils.java     | 12 ++++----
 .../cisd/common/utilities/ClassUtilsTest.java | 29 +++++++------------
 2 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java b/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java
index c836d52c5a7..e8ca3f8fe1b 100644
--- a/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java
+++ b/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java
@@ -16,6 +16,7 @@
 
 package ch.systemsx.cisd.common.utilities;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
@@ -44,7 +45,8 @@ public final class ClassUtils
     /**
      * For given <code>Class</code> returns a list of fields that are annotated with given <var>annotationClass</var>.
      */
-    public final static List<Field> getAnnotatedFieldList(final Class<?> clazz, final Class<?> annotationClass)
+    public final static List<Field> getAnnotatedFieldList(final Class<?> clazz,
+            final Class<? extends Annotation> annotationClass)
     {
         return getAnnotatedFieldList(clazz, annotationClass, null);
     }
@@ -54,11 +56,11 @@ public final class ClassUtils
      * 
      * @param fields if <code>null</code>, then a new <code>List</code> is created.
      */
-    private final static List<Field> getAnnotatedFieldList(final Class<?> clazz, final Class<?> annotationClass,
-            final List<Field> fields)
+    private final static List<Field> getAnnotatedFieldList(final Class<?> clazz,
+            final Class<? extends Annotation> annotationClass, final List<Field> fields)
     {
         assert clazz != null : "Unspecified class.";
-        assert annotationClass != null && annotationClass.isAnnotation() : "Unspecified or not an annotation class.";
+        assert annotationClass != null : "Unspecified or not an annotation class.";
         List<Field> list = fields;
         if (list == null)
         {
@@ -66,7 +68,7 @@ public final class ClassUtils
         }
         for (final Field field : clazz.getDeclaredFields())
         {
-            if (field.getAnnotation(BeanProperty.class) != null)
+            if (field.getAnnotation(annotationClass) != null)
             {
                 list.add(field);
             }
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java
index 6caf2b14dd1..47262b8d428 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java
@@ -59,13 +59,13 @@ public final class ClassUtilsTest
 
         public final String getMethodName()
         {
-            StackTraceElement[] elements = new Throwable().getStackTrace();
+            final StackTraceElement[] elements = new Throwable().getStackTrace();
             return elements[0].getMethodName();
         }
 
-        public final String getMethodName(Object one, Object two)
+        public final String getMethodName(final Object one, final Object two)
         {
-            StackTraceElement[] elements = new Throwable().getStackTrace();
+            final StackTraceElement[] elements = new Throwable().getStackTrace();
             return elements[0].getMethodName();
         }
     }
@@ -89,7 +89,7 @@ public final class ClassUtilsTest
     @Test
     public void testCreateWithDefaultConstructor()
     {
-        CharSequence cs = ClassUtils.create(CharSequence.class, StringBuffer.class.getName(), (Object[]) null);
+        final CharSequence cs = ClassUtils.create(CharSequence.class, StringBuffer.class.getName(), (Object[]) null);
         assertTrue(cs instanceof StringBuffer);
         assertEquals(0, cs.length());
     }
@@ -97,8 +97,8 @@ public final class ClassUtilsTest
     @Test
     public void testCreateWithPropertiesConstructor()
     {
-        Properties properties = new Properties();
-        Appendable appendable = ClassUtils.create(Appendable.class, MyClass.class.getName(), properties);
+        final Properties properties = new Properties();
+        final Appendable appendable = ClassUtils.create(Appendable.class, MyClass.class.getName(), properties);
         assertTrue(appendable instanceof MyClass);
         assertSame(properties, ((MyClass) appendable).properties);
     }
@@ -110,7 +110,7 @@ public final class ClassUtilsTest
         {
             ClassUtils.create(Float.class, Integer.class.getName(), (Object[]) null);
             fail("AssertionError expected.");
-        } catch (AssertionError e)
+        } catch (final AssertionError e)
         {
             assertEquals("Class 'java.lang.Integer' does not implements/extends 'java.lang.Float'.", e.getMessage());
         }
@@ -123,7 +123,7 @@ public final class ClassUtilsTest
         {
             ClassUtils.create(Float.class, CharSequence.class.getName(), (Object[]) null);
             fail("AssertionError expected.");
-        } catch (AssertionError e)
+        } catch (final AssertionError e)
         {
             assertEquals("Interface 'java.lang.CharSequence' can not be instanciated as it is an interface.", e
                     .getMessage());
@@ -183,13 +183,6 @@ public final class ClassUtilsTest
     @Test
     public final void testGetAnnotatedFieldList()
     {
-        try
-        {
-            ClassUtils.getAnnotatedFieldList(A.class, String.class);
-            fail("Not an annotation class.");
-        } catch (final AssertionError e)
-        {
-        }
         List<Field> fields = ClassUtils.getAnnotatedFieldList(A.class, BeanProperty.class);
         assertEquals(1, fields.size());
         fields = ClassUtils.getAnnotatedFieldList(B.class, BeanProperty.class);
@@ -220,17 +213,17 @@ public final class ClassUtilsTest
         // Appendable
         //
 
-        public Appendable append(char c) throws IOException
+        public Appendable append(final char c) throws IOException
         {
             return null;
         }
 
-        public Appendable append(CharSequence csq, int start, int end) throws IOException
+        public Appendable append(final CharSequence csq, final int start, final int end) throws IOException
         {
             return null;
         }
 
-        public Appendable append(CharSequence csq) throws IOException
+        public Appendable append(final CharSequence csq) throws IOException
         {
             return null;
         }
-- 
GitLab