KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > gems > StaticFactoryComponentAdapterTestCase


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 Leo Simmons & Joerg Schaible *
9  *****************************************************************************/

10 package org.picocontainer.gems;
11
12 import java.rmi.RemoteException JavaDoc;
13 import java.rmi.registry.LocateRegistry JavaDoc;
14 import java.rmi.registry.Registry JavaDoc;
15
16 import org.picocontainer.ComponentAdapter;
17 import org.picocontainer.defaults.DefaultPicoContainer;
18
19 import junit.framework.TestCase;
20
21 /**
22  * @author Jörg Schaible
23  */

24 public class StaticFactoryComponentAdapterTestCase
25         extends TestCase {
26
27     public void testStaticFactoryInAction() {
28         ComponentAdapter componentAdapter =
29             new StaticFactoryComponentAdapter(Registry JavaDoc.class,
30                     new StaticFactory() {
31                         public Object JavaDoc get() {
32                             try {
33                                 return LocateRegistry.getRegistry();
34                             } catch (RemoteException JavaDoc e) {
35                                 return null;
36                             }
37                         }
38             });
39         
40         DefaultPicoContainer pico = new DefaultPicoContainer();
41         pico.registerComponent(componentAdapter).verify(pico);
42         Registry JavaDoc registry = (Registry JavaDoc)pico.getComponentInstance(Registry JavaDoc.class);
43         assertNotNull(registry);
44     }
45 }
46
Popular Tags