jicarilla-sandbox/platform/container/impl/src/test/org/jicarilla/container/test/selectors ResolverSelectorTestCase.java,NONE,1.1

[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/selectors
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23127/platform/container/impl/src/test/org/jicarilla/container/test/selectors

Added Files:
	ResolverSelectorTestCase.java 
Log Message:
test coverage madness

--- NEW FILE: ResolverSelectorTestCase.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.selectors;

import org.jicarilla.container.selectors.ResolverSelector;
import org.jicarilla.container.selectors.ClassSelector;
import org.jicarilla.container.Resolver;
import org.jicarilla.container.ResolutionException;
import org.jicarilla.container.JicarillaIllegalAccessException;
import org.jicarilla.container.JicarillaInvocationTargetException;
import org.jicarilla.container.JicarillaInstantiationException;
import org.jicarilla.container.JicarillaClassNotFoundException;
import org.jicarilla.container.InitializationException;
import org.jicarilla.container.JicarillaException;
import org.jicarilla.container.tck.components.interfaces.Homer;
import org.jicarilla.container.tck.components.interfaces.HotdogBuyer;
import org.jicarilla.container.tck.components.type3.HomerImpl;
import org.jicarilla.framework.TrueSelector;
import org.easymock.MockControl;

import junit.framework.TestCase;

/**
 * 
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: ResolverSelectorTestCase.java,v 1.1 2004/03/14 21:32:26 lsimons Exp $
 */
public class ResolverSelectorTestCase extends TestCase
{
    MockControl resolverControl;
    Resolver resolver;

    MockControl resolver2Control;
    Resolver resolver2;

    ResolverSelector selector;
    ResolverSelector selector2;
    ResolverSelector selector3;
    ResolverSelector selector4;

    TrueSelector ts = new TrueSelector();

    public static class MockResolver implements Resolver
    {
        public Object get( Object key ) throws ResolutionException,
                JicarillaIllegalAccessException,
                JicarillaInvocationTargetException,
                JicarillaInstantiationException, JicarillaClassNotFoundException,
                InitializationException, JicarillaException
        {
            return null;
        }

        public Object[] getAll( Object key )
                throws JicarillaIllegalAccessException,
                JicarillaInvocationTargetException,
                JicarillaInstantiationException, JicarillaClassNotFoundException,
                InitializationException, JicarillaException
        {
            return new Object[0];
        }

        public boolean contains( Object key )
        {
            return false;
        }

        public void releaseInstance( Object instance ) throws Exception
        {
        }
    }

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

        resolver2Control = MockControl.createControl( Resolver.class );
        resolver2 = (Resolver)resolver2Control.getMock();

        selector = new ResolverSelector( resolver );
        selector2 = new ResolverSelector( resolver );
        selector3 = new ResolverSelector( resolver2 );
        selector4 = new ResolverSelector( resolver2 );
    }

    public void testSelect()
    {
        ResolverSelector selector = new ResolverSelector( resolver );

        resolver.contains( null );
        resolverControl.setReturnValue( false );
        resolver.contains( this );
        resolverControl.setReturnValue(false);
        resolver.contains( Homer.class );
        resolverControl.setReturnValue( true );
        resolverControl.replay();

        assertFalse(selector.select( null ) );
        assertFalse(selector.select( this ) );
        assertTrue(selector.select( Homer.class ) );

        resolverControl.verify();

    }

    public void testGetCriterion()
    {
        ResolverSelector selector = new ResolverSelector( resolver );
        assertEquals( resolver, selector.getCriterion() );
    }

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

    public void testEquals()
    {
        resolver = new MockResolver();
        resolver2 = new MockResolver();

        selector = new ResolverSelector( resolver );
        selector2 = new ResolverSelector( resolver );
        selector3 = new ResolverSelector( resolver2 );
        selector4 = new ResolverSelector( resolver2 );

        assertTrue( selector.equals( selector ) );
        assertTrue( selector.equals( selector2 ) );
        assertFalse( selector.equals( selector3 ) );
        assertFalse( selector.equals( selector4 ) );
        assertFalse( selector.equals( null ) );
        assertFalse( selector.equals( this ) );
        assertFalse( selector.equals( ts ) );

        assertFalse( selector3.equals( selector ) );
        assertFalse( selector3.equals( selector2 ) );
        assertTrue( selector3.equals( selector3 ) );
        assertTrue( selector3.equals( selector4 ) );
        assertFalse( selector3.equals( null ) );
        assertFalse( selector3.equals( this ) );
        assertFalse( selector3.equals( ts ) );
    }
    public void testHashCode()
    {
        resolver = new MockResolver();
        resolver2 = new MockResolver();

        selector = new ResolverSelector( resolver );
        selector2 = new ResolverSelector( resolver );
        selector3 = new ResolverSelector( resolver2 );
        selector4 = new ResolverSelector( resolver2 );

        assertEquals(
                selector.hashCode(),
                selector.hashCode()
        );
        assertEquals(
                selector.hashCode(),
                selector2.hashCode()
        );
        assertEquals(
                selector3.hashCode(),
                selector3.hashCode()
        );
        assertEquals(
                selector4.hashCode(),
                selector4.hashCode()
        );

        assertFalse( selector.hashCode() == selector3.hashCode() );
        assertFalse( selector.hashCode() == selector4.hashCode() );
        assertFalse( selector.hashCode() == -1 );
        assertFalse( selector.hashCode() == this.hashCode() );
        assertFalse( selector.hashCode() == ts.hashCode() );

        assertFalse( selector3.hashCode() == selector.hashCode() );
        assertFalse( selector3.hashCode() == selector2.hashCode() );
        assertFalse( selector3.hashCode() == -1 );
        assertFalse( selector3.hashCode() == this.hashCode() );
        assertFalse( selector3.hashCode() == ts.hashCode() );
    }
}



-------------------------------------------------------
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.