[jboss-cvs] JBossAS SVN: r93004 - in projects/annotations/trunk/core/src: test/java/org/jboss/annotations/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Aug 30 09:37:34 EDT 2009


Author: jesper.pedersen
Date: 2009-08-30 09:37:33 -0400 (Sun, 30 Aug 2009)
New Revision: 93004

Added:
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassInfoTests.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javalangreflect/unit/ClassInfoTestCase.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistclasspool/unit/ClassInfoTestCase.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistinputstream/unit/ClassInfoTestCase.java
Modified:
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ClassInfo.java
Log:
[JBANN-26] Add test suite for ClassInfo

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ClassInfo.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ClassInfo.java	2009-08-30 11:20:13 UTC (rev 93003)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ClassInfo.java	2009-08-30 13:37:33 UTC (rev 93004)
@@ -60,6 +60,9 @@
     */
    public ClassInfo(String className)
    {
+      if (className == null)
+         throw new IllegalArgumentException("ClassName is null");
+
       this.className = className;
       this.isInterface = false;
       this.isAbstract = false;
@@ -120,11 +123,17 @@
    {
       Collection<Annotation> result = new HashSet<Annotation>();
 
-      for (Collection<Annotation> c : annotations.values())
+      if (annotations != null)
       {
-         result.addAll(c);
+         for (Collection<Annotation> c : annotations.values())
+         {
+            result.addAll(c);
+         }
       }
 
+      if (result.size() == 0)
+         return null;
+
       return result;
    }
 
@@ -135,16 +144,28 @@
     */
    public Collection<Annotation> getAnnotations(String clz)
    {
+      if (clz == null)
+         throw new IllegalArgumentException("Clz is null");
+
+      if (annotations == null)
+         return null;
+
       return annotations.get(clz);
    }
 
    /**
     * Add an annotation
     * @param key The fully qualified class name of the annotation 
-    * @param a The annotation
+    * @param annotation The annotation
     */
-   public void addAnnotation(String key, Annotation a)
+   public void addAnnotation(String key, Annotation annotation)
    {
+      if (key == null)
+         throw new IllegalArgumentException("Key is null");
+
+      if (annotation == null)
+         throw new IllegalArgumentException("Annotation is null");
+
       if (annotations == null)
          annotations = new HashMap<String, Collection<Annotation>>(1);
 
@@ -152,7 +173,7 @@
       if (c == null)
          c = new HashSet<Annotation>(1);
 
-      c.add(a);
+      c.add(annotation);
 
       annotations.put(key, c);
    }
@@ -172,6 +193,9 @@
     */
    public void addChild(String clz)
    {
+      if (clz == null)
+         throw new IllegalArgumentException("Clz is null");
+
       if (children == null)
          children = new HashSet<String>(1);
 

Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassInfoTests.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassInfoTests.java	                        (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassInfoTests.java	2009-08-30 13:37:33 UTC (rev 93004)
@@ -0,0 +1,257 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-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.annotations.test;
+
+import org.jboss.annotations.Annotation;
+import org.jboss.annotations.AnnotationType;
+import org.jboss.annotations.impl.ClassInfo;
+
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for ClassInfo
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public abstract class ClassInfoTests extends AnnotationTests
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static Logger log = Logger.getLogger(ClassInfoTests.class.getName());
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Constructor: Null
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testConstructorNull() throws Throwable
+   {
+      try
+      {
+         ClassInfo ci = new ClassInfo(null);
+         fail("ClassName failed");
+      }
+      catch (Throwable t)
+      {
+         // Ok
+      }
+   }
+
+   /**
+    * Constructor: NotNull
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testConstructorNotNull() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+   }
+
+   /**
+    * Interface
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testInterface() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+      assertFalse(ci.isInterface());
+
+      ci.setInterface(true);
+      assertTrue(ci.isInterface());
+   }
+
+   /**
+    * Abstract
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testAbstract() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+      assertFalse(ci.isAbstract());
+
+      ci.setAbstract(true);
+      assertTrue(ci.isAbstract());
+   }
+
+   /**
+    * GetAnnotations: Null
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testGetAnnotationsNull() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+
+      assertNull(ci.getAnnotations());
+   }
+
+   /**
+    * GetAnnotations(String): Null
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testGetAnnotationsNameNull() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+
+      assertNull(ci.getAnnotations("annotation"));
+   }
+
+   /**
+    * AddAnnotation
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testAddAnnotation() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+
+      String key = "key";
+      Annotation annotation = new Annotation(key, new Object(), AnnotationType.CLASS,
+                                             ClassInfoTests.class.getName(), null, null);
+
+      try
+      {
+         ci.addAnnotation(null, annotation);
+         fail("Key failed");
+      }
+      catch (Throwable t)
+      {
+         // Ok
+      }
+
+      try
+      {
+         ci.addAnnotation(key, null);
+         fail("Annotation failed");
+      }
+      catch (Throwable t)
+      {
+         // Ok
+      }
+
+      ci.addAnnotation(key, annotation);
+
+      Collection<Annotation> c = ci.getAnnotations();
+      assertNotNull(c);
+      assertTrue("Size=" + c.size(), c.size() == 1);
+
+      c = ci.getAnnotations(key);
+      assertNotNull(c);
+      assertTrue("Size=" + c.size(), c.size() == 1);
+   }
+
+   /**
+    * GetChildren: Null
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testGetChildrenNull() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+
+      assertNull(ci.getChildren());
+   }
+
+   /**
+    * AddChild
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testAddChild() throws Throwable
+   {
+      String name = "myclass";
+
+      ClassInfo ci = new ClassInfo(name);
+
+      assertNotNull(ci);
+      assertEquals(name, ci.getClassName());
+
+      String key = "key";
+
+      try
+      {
+         ci.addChild(null);
+         fail("Key failed");
+      }
+      catch (Throwable t)
+      {
+         // Ok
+      }
+
+      ci.addChild(key);
+
+      Collection<String> c = ci.getChildren();
+      assertNotNull(c);
+      assertTrue("Size=" + c.size(), c.size() == 1);
+   }
+}

Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javalangreflect/unit/ClassInfoTestCase.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javalangreflect/unit/ClassInfoTestCase.java	                        (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javalangreflect/unit/ClassInfoTestCase.java	2009-08-30 13:37:33 UTC (rev 93004)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-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.annotations.test.javalangreflect.unit;
+
+import org.jboss.annotations.test.ClassInfoTests;
+
+import java.util.logging.Logger;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for ClassInfo
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class ClassInfoTestCase extends ClassInfoTests
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static Logger log = Logger.getLogger(ClassInfoTestCase.class.getName());
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+   }
+}

Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistclasspool/unit/ClassInfoTestCase.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistclasspool/unit/ClassInfoTestCase.java	                        (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistclasspool/unit/ClassInfoTestCase.java	2009-08-30 13:37:33 UTC (rev 93004)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-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.annotations.test.javassistclasspool.unit;
+
+import org.jboss.annotations.test.ClassInfoTests;
+
+import java.util.logging.Logger;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for ClassInfo
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class ClassInfoTestCase extends ClassInfoTests
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static Logger log = Logger.getLogger(ClassInfoTestCase.class.getName());
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+   }
+}

Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistinputstream/unit/ClassInfoTestCase.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistinputstream/unit/ClassInfoTestCase.java	                        (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/javassistinputstream/unit/ClassInfoTestCase.java	2009-08-30 13:37:33 UTC (rev 93004)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-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.annotations.test.javassistinputstream.unit;
+
+import org.jboss.annotations.test.ClassInfoTests;
+
+import java.util.logging.Logger;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for ClassInfo
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class ClassInfoTestCase extends ClassInfoTests
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static Logger log = Logger.getLogger(ClassInfoTestCase.class.getName());
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+   }
+}




More information about the jboss-cvs-commits mailing list