KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > gems > adapters > 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.adapters;
11
12 import junit.framework.TestCase;
13
14 import org.picocontainer.ComponentAdapter;
15 import org.picocontainer.defaults.DefaultPicoContainer;
16
17 import java.rmi.RemoteException JavaDoc;
18 import java.rmi.registry.LocateRegistry JavaDoc;
19 import java.rmi.registry.Registry JavaDoc;
20
21
22 /**
23  * @author Jörg Schaible
24  */

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