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