1 package org.picocontainer.tck;
2
3 import junit.framework.TestCase;
4 import org.picocontainer.PicoContainer;
5 import org.picocontainer.PicoInitializationException;
6 import org.picocontainer.PicoIntrospectionException;
7 import org.picocontainer.PicoRegistrationException;
8 import org.picocontainer.testmodel.DependsOnTouchable;
9 import org.picocontainer.testmodel.Touchable;
10 import org.picocontainer.defaults.UnsatisfiedDependencyInstantiationException;
11
12 import java.io.ByteArrayInputStream;
13 import java.io.ByteArrayOutputStream;
14 import java.io.IOException;
15 import java.io.ObjectInputStream;
16 import java.io.ObjectOutputStream;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 public abstract class AbstractBasicStringCompatabilityTestCase extends TestCase {
21
22 abstract public PicoContainer createPicoContainerWithTouchableAndDependency() throws
23 PicoRegistrationException, PicoIntrospectionException;
24
25 abstract public PicoContainer createPicoContainerWithTouchablesDependancyOnly() throws
26 PicoRegistrationException, PicoIntrospectionException;
27
28 public void testNotNull() throws PicoRegistrationException, PicoIntrospectionException {
29 assertNotNull("Are you calling super.setUp() in your setUp method?", createPicoContainerWithTouchableAndDependency());
30 }
31
32 public void testBasicInstantiationAndContainment() throws PicoInitializationException, PicoRegistrationException {
33 PicoContainer picoContainer = createPicoContainerWithTouchableAndDependency();
34 picoContainer.instantiateComponents();
35 assertTrue("Container should have Touchable component",
36 picoContainer.hasComponent("touchable"));
37 assertTrue("Container should have DependsOnTouchable component",
38 picoContainer.hasComponent("dependsOnTouchable"));
39 assertTrue("Component should be instance of Touchable",
40 picoContainer.getComponent("touchable") instanceof Touchable);
41 assertTrue("Component should be instance of DependsOnTouchable",
42 picoContainer.getComponent("dependsOnTouchable") instanceof DependsOnTouchable);
43 assertTrue("should not have non existent component", !picoContainer.hasComponent("doesNotExist"));
44 }
45
46 protected abstract void addAHashMapByInstance(PicoContainer picoContainer) throws PicoRegistrationException, PicoIntrospectionException;
47
48 public void testByInstanceRegistration() throws PicoRegistrationException, PicoInitializationException {
49 PicoContainer picoContainer = createPicoContainerWithTouchableAndDependency();
50 addAHashMapByInstance(picoContainer);
51 picoContainer.instantiateComponents();
52 assertEquals("Wrong number of comps in the internals", 3, picoContainer.getComponents().size());
53 assertEquals("Key - 'map', Impl - HashMap should be in internals", HashMap.class, picoContainer.getComponent("map").getClass());
54 //TODO - some way to test hashmap was passed in as an instance ?
55 // should unmanaged side of DefaultPicoContainer be more exposed thru interface?
56 }
57
58
59 }
This page was automatically generated by Maven