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 static org.junit.Assert.assertTrue;
012    
013    import java.util.Properties;
014    import java.util.List;
015    
016    import junit.framework.AssertionFailedError;
017    
018    import org.junit.Test;
019    import org.picocontainer.Characteristics;
020    import org.picocontainer.DefaultPicoContainer;
021    import org.picocontainer.MutablePicoContainer;
022    import org.picocontainer.PicoContainer;
023    import org.picocontainer.behaviors.Caching;
024    import org.picocontainer.behaviors.ImplementationHiding;
025    import org.picocontainer.injectors.ConstructorInjection;
026    import org.picocontainer.injectors.AdaptingInjection;
027    import org.picocontainer.tck.AbstractImplementationHidingPicoContainerTest;
028    
029    /**
030     *
031     * @author Aslak Hellesøy
032     */
033    public class ImplementationHidingWithDefaultPicoContainerTestCase extends AbstractImplementationHidingPicoContainerTest {
034    
035        protected MutablePicoContainer createImplementationHidingPicoContainer() {
036            return createPicoContainer(null);
037        }
038    
039        protected Properties[] getProperties() {
040            return new Properties[] {Characteristics.NO_CACHE, Characteristics.NO_HIDE_IMPL};
041        }
042    
043        // TODO (PH) should IH do caching at all and CtorInjection instead of AdaptingInjection ?
044    
045        protected void addDefaultComponentFactories(List expectedList) {
046            expectedList.add(Caching.class);
047            expectedList.add(ImplementationHiding.class);
048            expectedList.add(ConstructorInjection.class);
049        }
050    
051        protected MutablePicoContainer createPicoContainer(PicoContainer parent) {
052            return new DefaultPicoContainer(new Caching().wrap(new ImplementationHiding().wrap(new ConstructorInjection())), parent);
053        }
054    
055        @Test
056        public void testAggregatedVerificationException() {
057            super.testAggregatedVerificationException();    
058        }
059    
060        @Test public void testSameInstanceCanBeUsedAsDifferentTypeWhenCaching() {
061            // we're choosing a CAF for DPC, thus Caching (a default) not enabled.
062            try {
063                super.testSameInstanceCanBeUsedAsDifferentTypeWhenCaching();
064            } catch (AssertionFailedError e) {
065                assertTrue(e.getMessage().indexOf("expected same:<org.picocontainer.testmodel.WashableTouchable@") > -1);
066                assertTrue(e.getMessage().indexOf("was not:<org.picocontainer.testmodel.WashableTouchable@") > -1);
067            }
068    
069        }
070    
071        @Test public void testAcceptImplementsBreadthFirstStrategy() {
072            super.testAcceptImplementsBreadthFirstStrategy();
073        }
074    
075    }