[jboss-cvs] jbossretro/src/test/org/jboss/test/enums ...

Kabir Khan kkhan at jboss.com
Mon Jul 17 12:55:50 EDT 2006


  User: kkhan   
  Date: 06/07/17 12:55:50

  Added:       src/test/org/jboss/test/enums   UnloadedClass.java
                        UninitializedEnumTestCase.java
  Log:
  Use javassist getAvailableAnnotations() instead of getAnnotations() to avoid ClassNotFoundExceptions if the annotation is not on the classpath
  
  Make EnumImpl.valueOf() force initialization of the class if this has not happened already and a test for this border-line case
  
  Revision  Changes    Path
  1.1      date: 2006/07/17 16:55:50;  author: kkhan;  state: Exp;jbossretro/src/test/org/jboss/test/enums/UnloadedClass.java
  
  Index: UnloadedClass.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt 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.enums;
  
  /**
   * 
   * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
   * @version $Revision: 1.1 $
   */
  public class UnloadedClass
  {
     public States method() 
     {
        return null;
     }
  }
  
  
  
  1.1      date: 2006/07/17 16:55:50;  author: kkhan;  state: Exp;jbossretro/src/test/org/jboss/test/enums/UninitializedEnumTestCase.java
  
  Index: UninitializedEnumTestCase.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2005, JBoss Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt 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.enums;
  
  import java.lang.reflect.Method;
  
  import junit.framework.TestCase;
     
  /**
   * Tests of enums
   * @author Scott.Stark at jboss.org
   * @version $Revision: 1.1 $
   */
  public class UninitializedEnumTestCase extends TestCase
  {
     /**
      * Covers a specific use-case from container where the enum implementation failed
      */
     public void testUnloadedEnum() throws Exception
     {
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.test.enums.UnloadedClass");
        Method m = clazz.getMethod("method", new Class[0]);
        Class enoom = m.getReturnType();
        Object o = Enum.valueOf(enoom, "California");
        assertNotNull(o);
        assertTrue(o instanceof States);
        States st = (States)o;
        assertEquals("California", st.name());
        assertEquals(1, st.ordinal());
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list