KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > tck > AbstractComponentAdapterFactoryTestCase


1 /*****************************************************************************
2  * Copyright (C) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by *
9  *****************************************************************************/

10 package org.picocontainer.tck;
11
12 import junit.framework.TestCase;
13 import org.picocontainer.ComponentAdapter;
14 import org.picocontainer.PicoIntrospectionException;
15 import org.picocontainer.PicoRegistrationException;
16 import org.picocontainer.defaults.AssignabilityRegistrationException;
17 import org.picocontainer.defaults.ComponentAdapterFactory;
18 import org.picocontainer.defaults.DefaultPicoContainer;
19 import org.picocontainer.defaults.NotConcreteRegistrationException;
20 import org.picocontainer.testmodel.SimpleTouchable;
21 import org.picocontainer.testmodel.Touchable;
22
23 /**
24  * @author Aslak Hellesøy
25  * @version $Revision: 1234 $
26  */

27 public abstract class AbstractComponentAdapterFactoryTestCase extends TestCase {
28     protected DefaultPicoContainer picoContainer;
29
30     protected abstract ComponentAdapterFactory createComponentAdapterFactory();
31
32     protected void setUp() throws Exception JavaDoc {
33         picoContainer = new DefaultPicoContainer();
34     }
35
36     public void testEquals() throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
37         ComponentAdapter componentAdapter = createComponentAdapterFactory().createComponentAdapter(Touchable.class, SimpleTouchable.class, null);
38
39         assertEquals(componentAdapter, componentAdapter);
40         assertTrue(!componentAdapter.equals("blah"));
41     }
42
43     public void testRegisterComponent() throws PicoRegistrationException, AssignabilityRegistrationException {
44         ComponentAdapter componentAdapter =
45                 createComponentAdapterFactory().createComponentAdapter(Touchable.class, SimpleTouchable.class, null);
46
47         picoContainer.registerComponent(componentAdapter);
48
49         assertTrue(picoContainer.getComponentAdapters().contains(componentAdapter));
50     }
51
52     public void testUnregisterComponent() throws PicoRegistrationException, AssignabilityRegistrationException {
53         ComponentAdapter componentAdapter =
54                 createComponentAdapterFactory().createComponentAdapter(Touchable.class, SimpleTouchable.class, null);
55
56         picoContainer.registerComponent(componentAdapter);
57         picoContainer.unregisterComponent(Touchable.class);
58
59         assertFalse(picoContainer.getComponentAdapters().contains(componentAdapter));
60     }
61 }
62
Popular Tags