[jboss-cvs] JBossAS SVN: r90152 - in projects/jboss-mdr/trunk/src: main/java/org/jboss/metadata/plugins/signature and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 12 08:00:35 EDT 2009


Author: alesj
Date: 2009-06-12 08:00:35 -0400 (Fri, 12 Jun 2009)
New Revision: 90152

Added:
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/signature/SignatureEqualsUnitTestCase.java
Removed:
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/
Modified:
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/ContainerSPITestSuite.java
Log:
Code cleanup.

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java	2009-06-12 11:49:57 UTC (rev 90151)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java	2009-06-12 12:00:35 UTC (rev 90152)
@@ -114,11 +114,10 @@
     * @param declaringClass The Class declaring the method
     * @param methodName The name of the method
     * @param parameterTypes The parameters types accepted by the method
-    * @return 
+    * @return found declared method
     * @throws NoSuchMethodException If the method is not found in the <code>declaringClass</code>
     */
-   static Method findDeclaredMethod(final Class<?> declaringClass, final String methodName,
-         final Class<?>... parameterTypes) throws NoSuchMethodException
+   static Method findDeclaredMethod(final Class<?> declaringClass, final String methodName, final Class<?>... parameterTypes) throws NoSuchMethodException
    {
       SecurityManager sm = System.getSecurityManager();
       if (sm == null)
@@ -132,13 +131,11 @@
             {
                return declaringClass.getDeclaredMethod(methodName, parameterTypes);
             }
-
          });
       }
       catch (PrivilegedActionException pae)
       {
          throw (NoSuchMethodException) pae.getException();
       }
-
    }
 }

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java	2009-06-12 11:49:57 UTC (rev 90151)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java	2009-06-12 12:00:35 UTC (rev 90152)
@@ -24,12 +24,20 @@
 import java.util.Arrays;
 
 /**
- * 
+ * Common / helper to turn signature into string.
+ *
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
 public class SignatureNameUtil
 {
+   /**
+    * Append name and parameters.
+    *
+    * @param builder the string builder
+    * @param name the name
+    * @param parameters the parameters
+    */
    public static void signatureToString(StringBuilder builder, String name, String[] parameters)
    {
       if (name != null)
@@ -37,5 +45,4 @@
       if (parameters != null)
          builder.append(Arrays.asList(parameters));
    }
-
 }

Modified: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java	2009-06-12 11:49:57 UTC (rev 90151)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java	2009-06-12 12:00:35 UTC (rev 90152)
@@ -48,8 +48,9 @@
 {
 
    /**
-    * Constructor
-    * @param name
+    * Constructor.
+    *
+    * @param name the test name
     */
    public AnnotatedElementMetadataLoaderTestCase(String name)
    {
@@ -62,7 +63,7 @@
     * {@link AnnotatedElementMetaDataLoader}. The {@link AnnotatedElementMetaDataLoader} is
     * expected to find *no* annotations on that class
     *  
-    * @throws Exception
+    * @throws Exception for any error
     */
    public void testNoAnnotationPresent() throws Exception
    {
@@ -79,7 +80,7 @@
     * the presence of annotations on methods when a {@link DeclaredMethodSignature}
     * is used to create the {@link AnnotatedElementMetaDataLoader}
     * 
-    * @throws Exception
+    * @throws Exception for any error
     */
    public void testMethodLevelAnnotationsWithDeclaredMethodSignature() throws Exception
    {
@@ -103,8 +104,6 @@
       // should be empty array since the bean has no annotations
       Annotation[] annotationsOnMethodWithTwoAnnotations = anotherMetadata.getAnnotations();
       assertTrue("Expected two annotations on " + anotherDeclaredMethodSignature, annotationsOnMethodWithTwoAnnotations.length == 2);
-
-
    }
 
    /**
@@ -112,13 +111,13 @@
     * the presence of annotations on methods when a {@link MethodSignature}
     * is used to create the {@link AnnotatedElementMetaDataLoader}
     * 
-    * @throws Exception
+    * @throws Exception for any error
     */
    public void testMethodLevelAnnotationsWithMethodSignature() throws Exception
    {
       AnnotatedElementMetaDataLoader annotatedElementLoader = new AnnotatedElementMetaDataLoader(MethodBean.class);
       // Create a MethodSignature for the method with 1 annotation 
-      MethodSignature methodSignature = new MethodSignature("testAnnotation", new Class<?>[] {String.class});
+      MethodSignature methodSignature = new MethodSignature("testAnnotation", String.class);
       // create a retrieval out of it
       MetaDataRetrieval retrieval = annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature);
       MetaData metadata = new MetaDataRetrievalToMetaDataBridge(retrieval);
@@ -127,19 +126,12 @@
       assertTrue("Expected one annotation on testAnnotation method of " + MethodBean.class, annotations.length == 1);
       
       // Now try the same on a method which has 2 annotations
-      MethodSignature anotherMethodSignature = new MethodSignature("testAnnotation12", new Class<?>[] {String.class, Class.class});
+      MethodSignature anotherMethodSignature = new MethodSignature("testAnnotation12", String.class, Class.class);
       // create a retrieval out of it
       MetaDataRetrieval anotherRetrieval = annotatedElementLoader.getComponentMetaDataRetrieval(anotherMethodSignature);
       MetaData anotherMetadata = new MetaDataRetrievalToMetaDataBridge(anotherRetrieval);
       // should be empty array since the bean has no annotations
       Annotation[] annotationsOnMethodWithTwoAnnotations = anotherMetadata.getAnnotations();
       assertTrue("Expected two annotations on testAnnotation12 method of " + MethodBean.class, annotationsOnMethodWithTwoAnnotations.length == 2);
-
-
    }
-   
-    
-
-   
-
 }

Modified: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/ContainerSPITestSuite.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/ContainerSPITestSuite.java	2009-06-12 11:49:57 UTC (rev 90151)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/ContainerSPITestSuite.java	2009-06-12 12:00:35 UTC (rev 90152)
@@ -26,6 +26,7 @@
 import junit.textui.TestRunner;
 import org.jboss.test.metadata.spi.signature.JavassistSignatureTestCase;
 import org.jboss.test.metadata.spi.signature.SignatureTestCase;
+import org.jboss.test.metadata.spi.signature.SignatureEqualsUnitTestCase;
 
 /**
  * Container spi tests.
@@ -45,6 +46,7 @@
 
       suite.addTest(SignatureTestCase.suite());
       suite.addTest(JavassistSignatureTestCase.suite());
+      suite.addTest(SignatureEqualsUnitTestCase.suite());
 
       return suite;
    }

Copied: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/signature/SignatureEqualsUnitTestCase.java (from rev 90150, projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java)
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/signature/SignatureEqualsUnitTestCase.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/spi/signature/SignatureEqualsUnitTestCase.java	2009-06-12 12:00:35 UTC (rev 90152)
@@ -0,0 +1,91 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.metadata.spi.signature;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.test.BaseTestCase;
+
+/**
+ * Signature equality tests.
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SignatureEqualsUnitTestCase extends BaseTestCase
+{
+   public SignatureEqualsUnitTestCase(String s)
+   {
+      super(s);
+   }
+
+   public static Test suite()
+   {
+      return suite(SignatureEqualsUnitTestCase.class);
+   }
+
+   public void testEqualsMethodSignature() throws Exception
+   {
+      MethodSignature sig1 = getMethodSignature();
+      MethodSignature sig2 = getMethodSignature();
+      assertEquals(sig1.hashCode(), sig2.hashCode());
+      assertTrue(sig1.equals(sig2));
+      assertTrue(sig2.equals(sig1));
+   }
+   
+   public void testEqualsDeclaredMethodSignature() throws Exception
+   {
+      DeclaredMethodSignature sig1 = getDeclaredMethodSignature();
+      DeclaredMethodSignature sig2 = getDeclaredMethodSignature();
+      assertEquals(sig1.hashCode(), sig2.hashCode());
+      assertTrue(sig1.equals(sig2));
+      assertTrue(sig2.equals(sig1));
+   }
+   
+   public void testEqualsMethodSignatureAndDeclaredMethodSignature() throws Exception
+   {
+      MethodSignature ms = getMethodSignature();
+      DeclaredMethodSignature ds = getDeclaredMethodSignature();
+      assertEquals(ms.hashCode(), ds.hashCode());
+      assertTrue(ms.equals(ds));
+      assertTrue(ds.equals(ms));
+   }
+   
+   private MethodSignature getMethodSignature() throws Exception
+   {
+      return new MethodSignature(getMethod());
+   }
+   
+   private DeclaredMethodSignature getDeclaredMethodSignature() throws Exception
+   {
+      return new DeclaredMethodSignature(getMethod());
+   }
+   
+   private Method getMethod() throws Exception
+   {
+      Class<?> clazz = this.getClass();
+      return clazz.getDeclaredMethod("getMethod");
+   }
+}




More information about the jboss-cvs-commits mailing list