jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/builder SingletonType35HelperTestCase.java,NONE,1.1 KeyAwareAdapterHelperTestCase.java,NONE,1.1 ResolverHelperTestCase.java,NONE,1.1 ResolverProviderHelperTestCase.java,NONE,1.1
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/builder
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21681/platform/container/impl/src/test/org/jicarilla/container/test/builder
Added Files:
SingletonType35HelperTestCase.java
KeyAwareAdapterHelperTestCase.java ResolverHelperTestCase.java
ResolverProviderHelperTestCase.java
Log Message:
getting decent coverage now...
--- NEW FILE: SingletonType35HelperTestCase.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.builder;
import org.jicarilla.container.builder.SingletonType35Helper;
import org.jicarilla.container.builder.ResolverHelper;
import org.jicarilla.container.Resolver;
import org.jicarilla.container.KeyAwareAdapter;
import org.jicarilla.container.tck.components.type3.HomerImpl;
import org.jicarilla.container.tck.components.type3.MargeImpl;
import org.jicarilla.container.tck.components.interfaces.Marge;
import org.jicarilla.container.tck.components.interfaces.Homer;
import org.jicarilla.framework.Selector;
import org.easymock.MockControl;
import org.apache.avalon.framework.logger.Logger;
import junit.framework.TestCase;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: SingletonType35HelperTestCase.java,v 1.1 2004/03/17 19:31:09 lsimons Exp $
*/
public class SingletonType35HelperTestCase extends TestCase
{
MockControl resolverControl;
Resolver resolver;
public void setUp() throws Exception
{
super.setUp();
resolverControl = MockControl.createControl( Resolver.class );
resolver = (Resolver)resolverControl.getMock();
}
public void testGetAdapter() throws Exception
{
resolver.contains( Marge.class );
resolverControl.setReturnValue( true );
resolver.get( Marge.class );
resolverControl.setReturnValue( new MargeImpl() );
resolver.get(Logger.class );
resolverControl.setReturnValue( null );
resolverControl.replay();
SingletonType35Helper h = new SingletonType35Helper();
KeyAwareAdapter a = h.getAdapter( HomerImpl.class, resolver );
Object instance = a.getInstance( "blah" );
assertTrue( instance instanceof HomerImpl );
Object instance2 = a.getInstance( "blah" );
assertSame( instance, instance2 );
resolverControl.verify();
}
public void testGetAdapterDoesNotAcceptNullArgument() throws Exception
{
SingletonType35Helper helper = new SingletonType35Helper();
try
{
helper.getAdapter( null, resolver );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
try
{
helper.getAdapter( HomerImpl.class, null );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
}
public void testGetAdapterThrowsClassCastException() throws Exception
{
SingletonType35Helper helper = new SingletonType35Helper();
try
{
helper.getAdapter( this, resolver );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
public void testGetSelector() throws Exception
{
SingletonType35Helper h = new SingletonType35Helper();
Selector s = h.getSelector( HomerImpl.class );
assertTrue( s.select( Homer.class ) );
assertTrue( s.select( Homer.class.getName() ) );
assertFalse( s.select( null ) );
assertFalse( s.select( "blah" ) );
}
public void testGetSelectorDoesNotAcceptNullArgument() throws Exception
{
SingletonType35Helper helper = new SingletonType35Helper();
try
{
helper.getSelector( null );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
}
public void testGetSelectorThrowsClassCastException() throws Exception
{
SingletonType35Helper helper = new SingletonType35Helper();
try
{
helper.getSelector( this );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
}
--- NEW FILE: KeyAwareAdapterHelperTestCase.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.builder;
import org.jicarilla.container.builder.KeyAwareAdapterHelper;
import org.jicarilla.container.builder.AdapterHelper;
import org.jicarilla.container.Adapter;
import org.jicarilla.container.KeyAwareAdapter;
import org.jicarilla.framework.Selector;
import org.easymock.MockControl;
import junit.framework.TestCase;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: KeyAwareAdapterHelperTestCase.java,v 1.1 2004/03/17 19:31:09 lsimons Exp $
*/
public class KeyAwareAdapterHelperTestCase extends TestCase
{
MockControl adapterControl;
KeyAwareAdapter adapter;
public void setUp() throws Exception
{
super.setUp();
adapterControl = MockControl.createControl( KeyAwareAdapter.class );
adapter = (KeyAwareAdapter)adapterControl.getMock();
}
public void testGetAdapter() throws Exception
{
KeyAwareAdapterHelper helper = new KeyAwareAdapterHelper();
KeyAwareAdapter kaa = helper.getAdapter( adapter );
assertEquals( adapter, kaa );
}
public void testGetAdapterAcceptsNullArgument() throws Exception
{
KeyAwareAdapterHelper helper = new KeyAwareAdapterHelper();
KeyAwareAdapter a = helper.getAdapter( null );
assertNull( a );
}
public void testGetAdapterThrowsClassCastException() throws Exception
{
KeyAwareAdapterHelper helper = new KeyAwareAdapterHelper();
try
{
helper.getAdapter( this );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
public void testGetSelector() throws Exception
{
// TODO: this is not so good. Probably need a KeyAwareAdapterBasedSelector
adapter.getInstance( null );
adapterControl.setReturnValue( this );
adapter.releaseInstance( this );
adapterControl.replay();
KeyAwareAdapterHelper helper = new KeyAwareAdapterHelper();
Selector s = helper.getSelector( adapter );
assertNotNull( s );
assertTrue( s.select( this.getClass() ) );
assertTrue( s.select( this.getClass().getName() ) );
assertFalse( s.select( null ) ); // sanity checks
assertFalse( s.select( adapter ) );
assertFalse( s.select( helper ) );
adapterControl.verify();
}
public void testGetSelectorDoesNotAcceptNullArgument() throws Exception
{
KeyAwareAdapterHelper helper = new KeyAwareAdapterHelper();
try
{
helper.getSelector( null );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
}
public void testGetSelectorThrowsClassCastException() throws Exception
{
KeyAwareAdapterHelper helper = new KeyAwareAdapterHelper();
try
{
helper.getSelector( this );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
}
--- NEW FILE: ResolverProviderHelperTestCase.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.builder;
import org.jicarilla.container.builder.ResolverProviderHelper;
import org.jicarilla.container.builder.ResolverHelper;
import org.jicarilla.container.Resolver;
import org.jicarilla.container.KeyAwareAdapter;
import org.jicarilla.container.ResolverProvider;
import org.jicarilla.container.JicarillaException;
import org.jicarilla.framework.Selector;
import org.easymock.MockControl;
import junit.framework.TestCase;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: ResolverProviderHelperTestCase.java,v 1.1 2004/03/17 19:31:09 lsimons Exp $
*/
public class ResolverProviderHelperTestCase extends TestCase
{
MockControl resolverControl;
Resolver resolver;
ResolverProvider provider;
public void setUp() throws Exception
{
super.setUp();
resolverControl = MockControl.createControl( Resolver.class );
resolver = (Resolver)resolverControl.getMock();
provider = new ResolverProvider()
{
public Resolver getResolver() throws JicarillaException
{
return resolver;
}
};
}
public void testGetAdapter() throws Exception
{
String value = "booh!";
resolver.get( "blah" );
resolverControl.setReturnValue( value );
resolverControl.replay();
ResolverProviderHelper h = new ResolverProviderHelper();
KeyAwareAdapter a = h.getAdapter( provider );
assertEquals( value, a.getInstance( "blah" ) );
resolverControl.verify();
}
public void testGetAdapterDoesNotAcceptNullArgument() throws Exception
{
ResolverProviderHelper helper = new ResolverProviderHelper();
try
{
helper.getAdapter( null );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
}
public void testGetAdapterThrowsClassCastException() throws Exception
{
ResolverProviderHelper helper = new ResolverProviderHelper();
try
{
helper.getAdapter( this );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
public void testGetSelector() throws Exception
{
resolver.contains( "blah" );
resolverControl.setReturnValue( true );
resolverControl.replay();
ResolverProviderHelper helper = new ResolverProviderHelper();
Selector s = helper.getSelector( provider );
assertTrue( s.select( "blah" ) );
resolverControl.verify();
}
public void testGetSelectorDoesNotAcceptNullArgument() throws Exception
{
ResolverProviderHelper helper = new ResolverProviderHelper();
try
{
helper.getSelector( null );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
}
public void testGetSelectorThrowsClassCastException() throws Exception
{
ResolverProviderHelper helper = new ResolverProviderHelper();
try
{
helper.getSelector( this );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
}
--- NEW FILE: ResolverHelperTestCase.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.builder;
import org.jicarilla.container.builder.ResolverHelper;
import org.jicarilla.container.builder.BuilderHelper;
import org.jicarilla.container.builder.DefaultHelper;
import org.jicarilla.container.builder.EntryHelper;
import org.jicarilla.container.builder.DefaultBuilder;
import org.jicarilla.container.builder.ContainerAwareBuilderHelper;
import org.jicarilla.container.Resolver;
import org.jicarilla.container.KeyRelayingContainer;
import org.jicarilla.container.KeyAwareAdapter;
import org.jicarilla.container.adapters.ResolverBasedAdapter;
import org.jicarilla.framework.TrueSelector;
import org.jicarilla.framework.Selector;
import org.easymock.MockControl;
import junit.framework.TestCase;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: ResolverHelperTestCase.java,v 1.1 2004/03/17 19:31:09 lsimons Exp $
*/
public class ResolverHelperTestCase extends TestCase
{
MockControl resolverControl;
Resolver resolver;
public void setUp() throws Exception
{
super.setUp();
resolverControl = MockControl.createControl( Resolver.class );
resolver = (Resolver)resolverControl.getMock();
}
public void testGetAdapter() throws Exception
{
String value = "booh!";
resolver.get( "blah" );
resolverControl.setReturnValue( value );
resolverControl.replay();
ResolverHelper h = new ResolverHelper();
KeyAwareAdapter a = h.getAdapter( resolver );
assertEquals( value, a.getInstance( "blah" ) );
resolverControl.verify();
}
public void testGetAdapterDoesNotAcceptNullArgument() throws Exception
{
ResolverHelper helper = new ResolverHelper();
try
{
helper.getAdapter( null );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
}
public void testGetAdapterThrowsClassCastException() throws Exception
{
ResolverHelper helper = new ResolverHelper();
try
{
helper.getAdapter( this );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
public void testGetSelector() throws Exception
{
resolver.contains( "blah" );
resolverControl.setReturnValue( true );
resolverControl.replay();
ResolverHelper h = new ResolverHelper();
Selector s = h.getSelector( resolver );
assertTrue( s.select( "blah" ) );
resolverControl.verify();
}
public void testGetSelectorDoesNotAcceptNullArgument() throws Exception
{
ResolverHelper helper = new ResolverHelper();
try
{
helper.getSelector( null );
fail( "Expected an exception!" );
}
catch( AssertionError e ) {}
}
public void testGetSelectorThrowsClassCastException() throws Exception
{
ResolverHelper helper = new ResolverHelper();
try
{
helper.getSelector( this );
fail( "Expected an exception!" );
}
catch( ClassCastException e ) {}
}
}
-------------------------------------------------------
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