ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type TypeFactoryTest.java MyType2.java MyType1.java
Date Thu, 07 Feb 2002 10:36:43 GMT
donaldp     02/02/07 02:36:42

  Added:       proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type
                        TypeFactoryTest.java MyType2.java MyType1.java
  Log:
  Add in unit tests for the TypeFactory classes.
  
  Revision  Changes    Path
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/TypeFactoryTest.java
  
  Index: TypeFactoryTest.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.type;
  
  import java.io.File;
  import java.net.URL;
  import junit.framework.TestCase;
  
  /**
   * These are unit tests that test the basic operation of TypeFactorys.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/07 10:36:42 $
   */
  public class TypeFactoryTest
      extends TestCase
  {
      private final static String TYPE_NAME1 = "my-type1";
      private final static String TYPE_NAME2 = "my-type2";
      private final static Class TYPE_CLASS1 = MyType1.class;
      private final static Class TYPE_CLASS2 = MyType2.class;
      private final static String TYPE_CLASSNAME1 = TYPE_CLASS1.getName();
      private final static String TYPE_CLASSNAME2 = TYPE_CLASS2.getName();
  
      private final static String TYPE_JAR =
          "src/testcases/org/apache/myrmidon/interfaces/type/types.jar".replace( '/', File.separatorChar
);
  
      public TypeFactoryTest( final String name )
      {
          super( name );
      }
  
      /**
       * Make sure that you can load a basic type from DefaultTypeManager.
       */
      public void testBasicType()
      {
          final ClassLoader classLoader = getClass().getClassLoader();
          final DefaultTypeFactory factory = new DefaultTypeFactory( classLoader );
          factory.addNameClassMapping( TYPE_NAME2, TYPE_CLASSNAME2 );
  
          try
          {
              final Object type = factory.create( TYPE_NAME2 );
              final Class typeClass = type.getClass();
              assertEquals( "The type loaded for factory should be same class as in current
classloader",
                            typeClass, TYPE_CLASS2 );
          }
          catch( TypeException e )
          {
              fail( "Unable to create Type due to " + e );
          }
      }
  
      /**
       * Make sure that when you load a type from a RelaodableTypeFactory
       * that it is actually reloaded.
       */
      public void testReloadingTypeFactory()
          throws Exception
      {
          final File file = new File( TYPE_JAR );
          assertTrue( "Support Jar exists", file.exists() );
  
          final URL[] classpath = new URL[]{file.toURL()};
          final ClassLoader classLoader = getClass().getClassLoader();
          final ReloadingTypeFactory factory = new ReloadingTypeFactory( classpath, null );
          factory.addNameClassMapping( TYPE_NAME1, TYPE_CLASSNAME1 );
  
          try
          {
              final Object type = factory.create( TYPE_NAME1 );
              final Class typeClass = type.getClass();
              final boolean sameClass = typeClass == TYPE_CLASS1;
              assertTrue( "The type loaded for factory should not be same class as in current
classloader",
                          !sameClass );
          }
          catch( TypeException e )
          {
              fail( "Unable to create Type due to " + e );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/MyType2.java
  
  Index: MyType2.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.type;
  
  /**
   * A basic implementation of a type to test the type factory.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/07 10:36:42 $
   */
  public class MyType2
  {
      public boolean equals( final Object object )
      {
          return object.getClass() == getClass();
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/MyType1.java
  
  Index: MyType1.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.type;
  
  /**
   * A basic implementation of a type to test the type factory.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/07 10:36:42 $
   */
  public class MyType1
  {
      public boolean equals( final Object object )
      {
          return object.getClass() == getClass();
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message