Browse Source

Add in unit tests for the TypeFactory classes.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271202 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
f76be89106
6 changed files with 264 additions and 0 deletions
  1. +22
    -0
      proposal/myrmidon/src/test/org/apache/myrmidon/interfaces/type/MyType1.java
  2. +22
    -0
      proposal/myrmidon/src/test/org/apache/myrmidon/interfaces/type/MyType2.java
  3. +88
    -0
      proposal/myrmidon/src/test/org/apache/myrmidon/interfaces/type/TypeFactoryTest.java
  4. +22
    -0
      proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/MyType1.java
  5. +22
    -0
      proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/MyType2.java
  6. +88
    -0
      proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/TypeFactoryTest.java

+ 22
- 0
proposal/myrmidon/src/test/org/apache/myrmidon/interfaces/type/MyType1.java View File

@@ -0,0 +1,22 @@
/*
* 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$ $Date$
*/
public class MyType1
{
public boolean equals( final Object object )
{
return object.getClass() == getClass();
}
}

+ 22
- 0
proposal/myrmidon/src/test/org/apache/myrmidon/interfaces/type/MyType2.java View File

@@ -0,0 +1,22 @@
/*
* 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$ $Date$
*/
public class MyType2
{
public boolean equals( final Object object )
{
return object.getClass() == getClass();
}
}

+ 88
- 0
proposal/myrmidon/src/test/org/apache/myrmidon/interfaces/type/TypeFactoryTest.java View File

@@ -0,0 +1,88 @@
/*
* 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$ $Date$
*/
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 );
}
}
}

+ 22
- 0
proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/MyType1.java View File

@@ -0,0 +1,22 @@
/*
* 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$ $Date$
*/
public class MyType1
{
public boolean equals( final Object object )
{
return object.getClass() == getClass();
}
}

+ 22
- 0
proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/MyType2.java View File

@@ -0,0 +1,22 @@
/*
* 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$ $Date$
*/
public class MyType2
{
public boolean equals( final Object object )
{
return object.getClass() == getClass();
}
}

+ 88
- 0
proposal/myrmidon/src/testcases/org/apache/myrmidon/interfaces/type/TypeFactoryTest.java View File

@@ -0,0 +1,88 @@
/*
* 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$ $Date$
*/
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 );
}
}
}

Loading…
Cancel
Save