jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/adapters AbstracComponentAdapterTestCase.java,NONE,1.1 AdapterBasedKeyAwareAdapterTestCase.java,NONE,1.1 ResolverBasedAdapterTestCase.java,NONE,1.1 SingleUseComponentAdapterTestCase.java,1.4,1.5 SingletonComponentAdapterTestCase.java,1.4,1.5 ThreadLocalComponentAdapterTestCase.java,1.6,1.7 AbstractComponentAdapterTestCase.java,1.6,NONE

Leo Simons <[email protected]>
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/adapters
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7528/platform/container/impl/src/test/org/jicarilla/container/test/adapters

Modified Files:
	SingleUseComponentAdapterTestCase.java 
	SingletonComponentAdapterTestCase.java 
	ThreadLocalComponentAdapterTestCase.java 
Added Files:
	AbstracComponentAdapterTestCase.java 
	AdapterBasedKeyAwareAdapterTestCase.java 
	ResolverBasedAdapterTestCase.java 
Removed Files:
	AbstractComponentAdapterTestCase.java 
Log Message:
100% coverage on the adapters!

Index: SingletonComponentAdapterTestCase.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/adapters/SingletonComponentAdapterTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- SingletonComponentAdapterTestCase.java	10 Jan 2004 12:12:26 -0000	1.4
+++ SingletonComponentAdapterTestCase.java	16 Mar 2004 18:40:30 -0000	1.5
@@ -39,7 +39,7 @@
     public void testEverything() throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException
     {
         //TrueSelector selector = new TrueSelector();
-        AbstractComponentAdapterTestCase.LoggingFactory factory = new AbstractComponentAdapterTestCase.LoggingFactory();
+        AbstracComponentAdapterTestCase.LoggingFactory factory = new AbstracComponentAdapterTestCase.LoggingFactory();
 
         SingletonAdapter adapter = new SingletonAdapter(
                 factory );

Index: ThreadLocalComponentAdapterTestCase.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/adapters/ThreadLocalComponentAdapterTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ThreadLocalComponentAdapterTestCase.java	10 Jan 2004 12:12:26 -0000	1.6
+++ ThreadLocalComponentAdapterTestCase.java	16 Mar 2004 18:40:30 -0000	1.7
@@ -126,7 +126,7 @@
     public void testSingleThreaded() throws Exception
     {
         //TrueSelector selector = new TrueSelector();
-        AbstractComponentAdapterTestCase.LoggingFactory factory = new AbstractComponentAdapterTestCase.LoggingFactory();
+        AbstracComponentAdapterTestCase.LoggingFactory factory = new AbstracComponentAdapterTestCase.LoggingFactory();
 
         ThreadLocalAdapter adapter = new ThreadLocalAdapter( factory );
 

--- NEW FILE: AdapterBasedKeyAwareAdapterTestCase.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.container.test.adapters;

import org.jicarilla.container.adapters.AdapterBasedKeyAwareAdapter;
import org.jicarilla.container.Adapter;
import org.easymock.MockControl;

import junit.framework.TestCase;

/**
 * 
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: AdapterBasedKeyAwareAdapterTestCase.java,v 1.1 2004/03/16 18:40:30 lsimons Exp $
 */
public class AdapterBasedKeyAwareAdapterTestCase extends TestCase
{
    MockControl adapterControl;
    Adapter adapter;

    public void setUp() throws Exception
    {
        super.setUp();

        adapterControl = MockControl.createControl( Adapter.class );
        adapter = (Adapter)adapterControl.getMock();
    }

    public void testConstructor()
    {
        assertNotNull( new AdapterBasedKeyAwareAdapter( adapter ) );

        try
        {
            new AdapterBasedKeyAwareAdapter( null );
            fail( "Expected an exception!" );
        }
        catch( AssertionError ae ) {}
    }

    public void testGetInstance()
    {
        RuntimeException ex = new RuntimeException();
        adapter.getInstance();
        adapterControl.setReturnValue( this );
        adapter.getInstance();
        adapterControl.setThrowable( ex );
        adapterControl.replay();

        assertEquals( this, new AdapterBasedKeyAwareAdapter( adapter ).getInstance( "blah" ) );
        try
        {
            new AdapterBasedKeyAwareAdapter( adapter ).getInstance( null );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( ex, th );
        }
    }

    public void testRelease() throws Exception
    {
        RuntimeException ex = new RuntimeException();
        adapter.releaseInstance( this );
        adapter.releaseInstance( null );
        adapterControl.setThrowable( ex );
        adapterControl.replay();

        new AdapterBasedKeyAwareAdapter( adapter ).releaseInstance( this );
        try
        {
            new AdapterBasedKeyAwareAdapter( adapter ).releaseInstance( null );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( ex, th );
        }
    }
}

--- NEW FILE: ResolverBasedAdapterTestCase.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.container.test.adapters;

import org.jicarilla.container.adapters.ResolverBasedAdapter;
import org.jicarilla.container.Resolver;
import org.easymock.MockControl;

import junit.framework.TestCase;

/**
 * 
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: ResolverBasedAdapterTestCase.java,v 1.1 2004/03/16 18:40:30 lsimons Exp $
 */
public class ResolverBasedAdapterTestCase extends TestCase
{
    MockControl resolverControl;
    Resolver resolver;

    public void setUp() throws Exception
    {
        super.setUp();
        resolverControl = MockControl.createControl( Resolver.class );
        resolver = (Resolver)resolverControl.getMock();
    }

    public void testConstructor()
    {
        assertNotNull( new ResolverBasedAdapter(resolver) );
        try
        {
            new ResolverBasedAdapter(null);
            fail( "Expected an exception!" );
        }
        catch( AssertionError ae ) {}

    }

    public void testGetInstance()
    {
        RuntimeException re = new RuntimeException();
        resolver.get( "blah" );
        resolverControl.setReturnValue( this );
        resolver.get( null );
        resolverControl.setThrowable( re );
        resolverControl.replay();

        ResolverBasedAdapter adapter = new ResolverBasedAdapter( resolver );

        assertEquals( this, adapter.getInstance( "blah" ) );
        try
        {
            adapter.getInstance( null );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( re, th );
        }

        resolverControl.verify();
    }

    public void testReleaseInstance() throws Exception
    {
        Exception e = new Exception();
        resolver.releaseInstance( this );
        resolver.releaseInstance( null );
        resolverControl.setThrowable( e );
        resolverControl.replay();

        ResolverBasedAdapter adapter = new ResolverBasedAdapter( resolver );

        adapter.releaseInstance( this );
        try
        {
            adapter.releaseInstance( null );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( e, th );
        }

        resolverControl.verify();
    }
}

Index: SingleUseComponentAdapterTestCase.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/adapters/SingleUseComponentAdapterTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- SingleUseComponentAdapterTestCase.java	10 Jan 2004 12:12:26 -0000	1.4
+++ SingleUseComponentAdapterTestCase.java	16 Mar 2004 18:40:30 -0000	1.5
@@ -39,7 +39,7 @@
     public void testEverything() throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException
     {
         //TrueSelector selector = new TrueSelector();
-        AbstractComponentAdapterTestCase.LoggingFactory factory = new AbstractComponentAdapterTestCase.LoggingFactory();
+        AbstracComponentAdapterTestCase.LoggingFactory factory = new AbstracComponentAdapterTestCase.LoggingFactory();
 
         SingleUseAdapter adapter = new SingleUseAdapter(
                 factory );

--- NEW FILE: AbstracComponentAdapterTestCase.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.container.test.adapters;

import junit.framework.TestCase;
import org.jicarilla.container.Factory;
import org.jicarilla.container.JicarillaException;
import org.jicarilla.container.JicarillaInstantiationException;
import org.jicarilla.container.adapters.AbstractAdapter;

/**
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: AbstracComponentAdapterTestCase.java,v 1.1 2004/03/16 18:40:30 lsimons Exp $
 */
public class AbstracComponentAdapterTestCase extends TestCase
{
    public static class Adapter extends AbstractAdapter
    {
        public Adapter( Factory factory )
        {
            super( factory );
        }

        public Object getInstance()
        {
            return m_factory.newInstance();
        }
    }

    public static class LoggingFactory implements Factory
    {
        public boolean newInstanceCalled = false;
        public boolean releaseInstanceCalled = false;

        public Object newInstance()
        {
            newInstanceCalled = true;
            return new Object();
        }

        public void releaseInstance( Object o ) throws Exception
        {
            releaseInstanceCalled = true;
        }
    }

    public void testEverything() throws Exception
    {
        LoggingFactory factory = new LoggingFactory();
        Adapter adapter = new Adapter( factory );

        Object instance = adapter.getInstance();
        adapter.releaseInstance( instance );

        assertTrue( factory.newInstanceCalled );
        assertTrue( factory.releaseInstanceCalled );

        factory = new LoggingFactory();
        adapter = new Adapter( factory );
        adapter.releaseInstance( null );
        assertTrue( factory.releaseInstanceCalled );
    }

    public void testExceptions()
    {
        Throwable t = null;
        try
        {
            new Adapter( null );
        }
        catch( AssertionError th )
        {
            t = th;
        }
        assertNotNull( t );
    }

    public void testHandleUnExpectedException()
    {
        JicarillaException ex = new JicarillaException();
        try
        {
            AbstractAdapter.handleUnexpectedException( ex );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( ex, th );
        }

        Error e = new Error();
        try
        {
            AbstractAdapter.handleUnexpectedException( e );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( e, th );
        }

        Exception exc = new Exception();
        try
        {
            AbstractAdapter.handleUnexpectedException( exc );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertTrue( th instanceof JicarillaInstantiationException );
            assertEquals( exc, th.getCause() );
        }

    }

    public void testHandleUnExpectedExceptionFromSubClass()
    {
        LoggingFactory factory = new LoggingFactory();
        Adapter adapter = new Adapter( factory );

        JicarillaException ex = new JicarillaException();
        try
        {
            adapter.handleUnexpectedException( ex );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( ex, th );
        }

        Error e = new Error();
        try
        {
            adapter.handleUnexpectedException( e );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertEquals( e, th );
        }

        Exception exc = new Exception();
        try
        {
            adapter.handleUnexpectedException( exc );
            fail( "Expected an exception!" );
        }
        catch( Throwable th )
        {
            assertTrue( th instanceof JicarillaInstantiationException );
            assertEquals( exc, th.getCause() );
        }

    }
}

--- AbstractComponentAdapterTestCase.java DELETED ---



-------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.