001    /*****************************************************************************
002     * Copyright (C) PicoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     *****************************************************************************/
009    package org.picocontainer.containers;
010    
011    import org.picocontainer.MutablePicoContainer;
012    import org.picocontainer.PicoContainer;
013    import org.picocontainer.behaviors.ImplementationHidingBehaviorFactory;
014    import org.picocontainer.behaviors.CachingBehaviorFactory;
015    import org.picocontainer.injectors.ConstructorInjectionFactory;
016    import org.picocontainer.DefaultPicoContainer;
017    import org.picocontainer.tck.AbstractImplementationHidingPicoContainerTestCase;
018    
019    import junit.framework.AssertionFailedError;
020    
021    /**
022     *
023     * @author Aslak Hellesøy
024     */
025    public class ImplementationHidingWithDefaultPicoContainerTestCase extends AbstractImplementationHidingPicoContainerTestCase {
026    
027        protected MutablePicoContainer createImplementationHidingPicoContainer() {
028            return createPicoContainer(null);
029        }
030    
031        protected MutablePicoContainer createPicoContainer(PicoContainer parent) {
032            return new DefaultPicoContainer(new CachingBehaviorFactory().forThis(new ImplementationHidingBehaviorFactory().forThis(new ConstructorInjectionFactory())), parent);
033        }
034        
035        public void testSameInstanceCanBeUsedAsDifferentTypeWhenCaching() {
036            // we're choosing a CAF for DPC, thus Caching (a default) not enabled.
037            try {
038                super.testSameInstanceCanBeUsedAsDifferentTypeWhenCaching();
039            } catch (AssertionFailedError e) {
040                assertTrue(e.getMessage().indexOf("expected same:<org.picocontainer.testmodel.WashableTouchable@") > -1);
041                assertTrue(e.getMessage().indexOf("was not:<org.picocontainer.testmodel.WashableTouchable@") > -1);
042            }
043    
044        }
045    }