public void testShouldCreateBowlWithoutTom() {
// START SNIPPET: individualSelection
MutablePicoContainer mpc = new DefaultPicoContainer();
mpc.registerComponentImplementation("Tom", Cod.class);
mpc.registerComponentImplementation("Dick", Cod.class);
mpc.registerComponentImplementation("Harry", Cod.class);
mpc.registerComponentImplementation("Sharky", Shark.class);
mpc.registerComponentImplementation(Bowl.class, Bowl.class, new Parameter[]{
new CollectionComponentParameter(Fish.class, false),
new CollectionComponentParameter(Cod.class, false) {
protected boolean evaluate(ComponentAdapter adapter) {
return !"Tom".equals(adapter.getComponentKey());
}
}
});
Cod tom = (Cod) mpc.getComponentInstance("Tom");
Bowl bowl = (Bowl) mpc.getComponentInstance(Bowl.class);
assertTrue(bowl.fishes.values().contains(tom));
assertFalse(bowl.cods.values().contains(tom));
// END SNIPPET: individualSelection
}