1 package org.neo.swarm.core.aop.silc;
2
3 import junit.framework.TestCase;
4 import org.picocontainer.defaults.*;
5 import org.picocontainer.ComponentAdapter;
6 import org.picocontainer.PicoInitializationException;
7 import org.picocontainer.PicoIntrospectionException;
8 import org.easymock.MockControl;
9 import org.neo.swarm.Fred;
10 import org.neo.swarm.FredImpl;
11 import org.neo.swarm.core.aop.AspectContainer;
12 import org.neo.swarm.core.aop.silc.SilcAspectComponentAdapter;
13 import org.neo.swarm.core.aop.silc.comp.AspectComponentImpl;
14
15 public class SilcAspectComponentAdapterTest extends TestCase {
16
17 public void testDoSomething() {
18 MockControl control = MockControl.createStrictControl(AspectContainer.class);
19 AspectContainer aspects = (AspectContainer) control.getMock();
20 Fred f = new FredImpl("blah");
21 SilcAspectComponentAdapter adapter = new SilcAspectComponentAdapter(
22 new StubComponentAdapter(new ConstructorInjectionComponentAdapter("key", FredImpl.class),f),aspects);
23
24 AspectComponentImpl c = null;
25 aspects.weave(c);
26 control.setMatcher(MockControl.ALWAYS_MATCHER);
27
28
29 control.replay();
30
31 Fred fred = (Fred) adapter.getComponentInstance();
32 assertNotNull(fred);
33
34
35 control.verify();
36 }
37
38
39 static class StubComponentAdapter extends DecoratingComponentAdapter {
40 private Object instance;
41
42 public StubComponentAdapter(ComponentAdapter componentAdapter, Object instance) {
43 super(componentAdapter);
44 this.instance = instance;
45 }
46
47 public Object getComponentInstance() throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
48 return instance;
49 }
50 }
51
52 }