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 * Idea by Rachel Davies, Original code by Stacy Curl *
009 *****************************************************************************/
010
011 package org.picocontainer.defaults;
012
013 import org.picocontainer.ComponentAdapter;
014 import org.picocontainer.PicoInitializationException;
015 import org.picocontainer.PicoIntrospectionException;
016 import org.picocontainer.tck.AbstractComponentAdapterFactoryTestCase;
017 import org.picocontainer.testmodel.SimpleTouchable;
018 import org.picocontainer.testmodel.Touchable;
019
020 public class DefaultComponentAdapterFactoryTestCase extends AbstractComponentAdapterFactoryTestCase {
021 protected ComponentAdapterFactory createComponentAdapterFactory() {
022 return new DefaultComponentAdapterFactory();
023 }
024
025 public void testInstantiateComponentWithNoDependencies() throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
026 ComponentAdapter componentAdapter =
027 createComponentAdapterFactory().createComponentAdapter(Touchable.class, SimpleTouchable.class, null);
028
029 Object comp = componentAdapter.getComponentInstance(new DefaultPicoContainer());
030 assertNotNull(comp);
031 assertTrue(comp instanceof SimpleTouchable);
032 }
033
034 public void testSingleUsecanBeInstantiatedByDefaultComponentAdapter() {
035 ComponentAdapter componentAdapter = createComponentAdapterFactory().createComponentAdapter("o", Object.class, null);
036 Object component = componentAdapter.getComponentInstance(new DefaultPicoContainer());
037 assertNotNull(component);
038 }
039 }