Re: [picocontainer-dev] new ComponentMonitor method ...
Paul Hammant <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
Here's a testcase that illustrates it in use -
@Test public void
canInterceptImplementationViaNewInjectionFactoryMethodOnMonitor() {
DefaultPicoContainer dpc = new DefaultPicoContainer(new
MyNullComponentMonitor());
dpc.addComponent(List.class, ArrayList.class);
assertNotNull(dpc.getComponent(List.class));
assertEquals("doppleganger",
dpc.getComponent(List.class).get(0));
}
private static class MyNullComponentMonitor extends
NullComponentMonitor {
public AbstractInjector newInjectionFactory(AbstractInjector
abstractInjector) {
return new AbstractInjector(List.class, ArrayList.class,
Parameter.DEFAULT, MyNullComponentMonitor.this, null, false) {
public void verify(PicoContainer container) throws
PicoCompositionException {
}
public Object getComponentInstance(PicoContainer
container) throws PicoCompositionException {
ArrayList list = new ArrayList();
list.add("doppleganger");
return list;
}
public String getDescriptor() {
return "n/a";
}
};
}
}
On Mar 22, 2008, at 5:41 PM, Paul Hammant wrote:
> AbstractInjector newInjectionFactory(AbstractInjector
> abstractInjector);
>
> Implementations return what is passed in by default (see patch)
>
> Useful for unit (integration) testing. You might have a large tree
> of containers and components, but want to swap out something crucial
> for a Stub or a Mock so that you integration testing is not going to
> bring up the whole app (just a subset of the components). This on
> ComponentMonitor will allow that, as long at the CM instance is
> passed into the root container.
>
> Thoughts?
>
> - Paul
>
> <new-monitor-method.patch>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email