jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/util Type2UtilTestCase.java,1.2,1.3
[email protected] Tue, 09 Mar 2004 16:00:01 -0800
Newsgroups
gmane.comp.java.jicarilla.cvs
Message-ID
<[email protected] >
Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12008/platform/container/impl/src/test/org/jicarilla/container/test/util
Modified Files:
Type2UtilTestCase.java
Log Message:
minor api improvements + tests
Index: Type2UtilTestCase.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/util/Type2UtilTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Type2UtilTestCase.java 9 Mar 2004 20:33:34 -0000 1.2
+++ Type2UtilTestCase.java 9 Mar 2004 23:59:59 -0000 1.3
@@ -28,6 +28,7 @@
import org.easymock.MockControl;
import org.jicarilla.container.DefaultContainer;
import org.jicarilla.container.Resolver;
+import org.jicarilla.container.UnsatisfiableDependencyException;
import org.jicarilla.container.tck.AbstractTCKTestCase;
import org.jicarilla.container.tck.components.interfaces.Homer;
import org.jicarilla.container.tck.components.interfaces.Marge;
@@ -62,26 +63,17 @@
*/
public class Type2UtilTestCase extends AbstractTCKTestCase
{
- static
+ MockControl resolverControl;
+ Resolver resolver;
+
+ public void setUp() throws Exception
{
- try
- {
- Type2UtilTestCase.margeAware = MargeAware.class.getMethod( "setMarge", new Class[] { Marge.class } );
- Type2UtilTestCase.homerAware = HomerAware.class.getMethod( "setHomer", new Class[] { Homer.class } );
- Type2UtilTestCase.bartAware = BartAware.class.getMethod( "setBart", new Class[] { Bart.class } );
- Type2UtilTestCase.lisaAware = LisaAware.class.getMethod( "setLisa", new Class[] { Lisa.class } );
- Type2UtilTestCase.maggieAware = MaggieAware.class.getMethod( "setMaggie", new Class[] { Maggie.class } );
- }
- catch( NoSuchMethodException e )
- {
- throw new CascadingRuntimeException( "bug in testcase", e );
- }
+ super.setUp();
+
+ resolverControl = MockControl.createControl( Resolver.class );
+ resolver = (Resolver)resolverControl.getMock();
}
- public static Method margeAware;
- public static Method homerAware;
- public static Method bartAware;
- public static Method lisaAware;
- public static Method maggieAware;
+
// ----------------------------------------------------------------------
// Test: getAwarenessMethods()
// ----------------------------------------------------------------------
@@ -354,6 +346,159 @@
assertEquals( Homer.class, classes[0] );
}
+ // ----------------------------------------------------------------------
+ // Test: checkDependenciesAreSatisfiable()
+ // ----------------------------------------------------------------------
+
+ public void testCheckDependenciesAreSatisfiableOnSimpleAwareClass()
+ throws Exception
+ {
+ resolver.contains( Marge.class );
+ resolverControl.setReturnValue( true );
+ resolverControl.replay();
+
+ Method[] methods = Type2Util.getAwarenessMethods(
+ HomerImpl.class );
+
+ try
+ {
+ Type2Util.checkDepencenciesAreSatisfiable( HomerImpl.class,
+ methods, resolver );
+ }
+ catch( UnsatisfiableDependencyException ude )
+ {
+ fail();
+ }
+ resolverControl.verify();
+ }
+
+ public void testCheckDependenciesAreSatisfiableDoesNotAcceptNullClassArgumentWhenThereIsNoProblem()
+ {
+ resolverControl.replay();
+
+ Method[] methods = Type2Util.getAwarenessMethods(
+ HomerImpl.class );
+
+ try
+ {
+ Type2Util.checkDepencenciesAreSatisfiable( null,
+ methods, resolver );
+ fail();
+ }
+ catch( AssertionError ae )
+ {
+ }
+ resolverControl.verify();
+ }
+
+ public void testCheckDependenciesAreSatisfiableDoesNotAcceptNullClassArgumentWhenThereIsAProblem()
+ {
+ resolverControl.replay();
+
+ Method[] methods = Type2Util.getAwarenessMethods(
+ HomerImpl.class );
+
+ try
+ {
+ Type2Util.checkDepencenciesAreSatisfiable( null,
+ methods, resolver );
+ fail();
+ }
+ catch( AssertionError ae )
+ {
+ }
+
+ resolverControl.verify();
+ }
+
+ public void testCheckDependenciesAreSatisfiableThrowsExceptionForNullMethodsArgument()
+ {
+ resolverControl.replay();
+ try
+ {
+ Type2Util.checkDepencenciesAreSatisfiable( HomerImpl.class, null,
+ resolver );
+ fail( "Expected an exception!" );
+ }
+ catch( AssertionError ae ) {}
+ resolverControl.verify();
+ }
+
+ public void testCheckDependenciesAreSatisfiableAcceptsEmptyMethodsArgument()
+ {
+ resolverControl.replay();
+ try
+ {
+ Type2Util.checkDepencenciesAreSatisfiable( HomerImpl.class, new Method[0],
+ resolver );
+ }
+ catch( UnsatisfiableDependencyException ude )
+ {
+ fail();
+ }
+ resolverControl.verify();
+ }
+
+ public void testCheckDependenciesAreSatisfiableThrowsExceptionForNullResolverArgument()
+ {
+ resolverControl.replay();
+ try
+ {
+ Type2Util.checkDepencenciesAreSatisfiable( HomerImpl.class, new Method[0],
+ null );
+ fail( "Expected an exception!" );
+ }
+ catch( AssertionError ae ) {}
+ resolverControl.verify();
+ }
+
+ public void testCheckDependenciesAreSatisfiableFailureThrowsVerboseError()
+ {
+ resolver.contains( Marge.class );
+ resolverControl.setReturnValue( false );
+ resolverControl.replay();
+
+ Method[] methods = Type2Util.getAwarenessMethods(
+ HomerImpl.class );
+
+ try
+ {
+ Type2Util.checkDepencenciesAreSatisfiable( HomerImpl.class, methods,
+ resolver );
+ fail( "Expected an exception!" );
+ }
+ catch( UnsatisfiableDependencyException ude )
+ {
+ assertEquals( HomerImpl.class, ude.getProblematicClass() );
+ Class[] causes = (Class[])ude.getUnsatisfiedDependencies().toArray( new Class[0] );
+ assertEquals( 1, causes.length );
+ assertEquals( Marge.class, causes[0] );
+ }
+ resolverControl.verify();
+ }
+
+ // OLD TESTS...
+
+ static
+ {
+ try
+ {
+ Type2UtilTestCase.margeAware = MargeAware.class.getMethod( "setMarge", new Class[] { Marge.class } );
+ Type2UtilTestCase.homerAware = HomerAware.class.getMethod( "setHomer", new Class[] { Homer.class } );
+ Type2UtilTestCase.bartAware = BartAware.class.getMethod( "setBart", new Class[] { Bart.class } );
+ Type2UtilTestCase.lisaAware = LisaAware.class.getMethod( "setLisa", new Class[] { Lisa.class } );
+ Type2UtilTestCase.maggieAware = MaggieAware.class.getMethod( "setMaggie", new Class[] { Maggie.class } );
+ }
+ catch( NoSuchMethodException e )
+ {
+ throw new CascadingRuntimeException( "bug in testcase", e );
+ }
+ }
+ public static Method margeAware;
+ public static Method homerAware;
+ public static Method bartAware;
+ public static Method lisaAware;
+ public static Method maggieAware;
// ----------------------------------------------------------------------
// Test: getAwarenessMethods() / callAwarenessMethods()
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click