1   package org.neo.swarm;
2   
3   import junit.framework.TestCase;
4   import org.easymock.MockControl;
5   import org.neo.swarm.ApplicationContext;
6   import org.neo.swarm.DefaultSwarmContainer;
7   
8   import java.util.LinkedList;
9   import java.util.List;
10  
11  public class NewSwarmContainerTest extends TestCase {
12  
13      public void test() throws Exception {
14          MockControl appContextControl = MockControl.createStrictControl(ApplicationContext.class);
15          ApplicationContext appContextMock = (ApplicationContext) appContextControl.getMock();
16  
17          MockControl servicesControl = MockControl.createStrictControl(ApplicationContext.class);
18          ApplicationContext servicesMock = (ApplicationContext) servicesControl.getMock();
19  
20          DefaultSwarmContainer container = new DefaultSwarmContainer(appContextMock, servicesMock);
21  
22  
23          MockControl otherAppContextControl =  MockControl.createStrictControl(ApplicationContext.class);
24          ApplicationContext otherAppContextMock = (ApplicationContext) otherAppContextControl.getMock();
25          List l = new LinkedList();
26          l.add(otherAppContextMock);
27          l.add(otherAppContextMock);
28          //record
29          appContextControl.expectAndReturn(appContextMock.retrieveComponentsOfType(ApplicationContext.class),l);
30          otherAppContextControl.expectAndReturn(otherAppContextMock.retrieveComponent("key"), null);
31          otherAppContextControl.expectAndReturn(otherAppContextMock.retrieveComponent("key"), new FredImpl("do"));
32  
33          //replay
34          appContextControl.replay();
35          otherAppContextControl.replay();
36          servicesControl.replay();
37          assertNotNull(container.getComponent("key"));
38  
39          //verify
40          appContextControl.verify();
41          servicesControl.verify();
42          otherAppContextControl.verify();
43      }
44  }