* @author Konstantin Pribluda ( konstantin.pribluda(at)infodesire.com )
* @author Aslak Hellesøy
*/
public class DefaultContainerRecorderTestCase extends TestCase {
public void testInvocationsCanBeRecordedAndReplayedOnADifferentContainerInstance() throws Exception {
ContainerRecorder recorder = new DefaultContainerRecorder(new DefaultNanoPicoContainer());
MutablePicoContainer recorded = recorder.getContainerProxy();
recorded.registerComponentInstance("fruit", "apple");
recorded.registerComponentInstance("int", new Integer(239));
recorded.registerComponentImplementation("thing",
ThingThatTakesParamsInConstructor.class,
new Parameter[]{
ComponentParameter.DEFAULT,
ComponentParameter.DEFAULT,
});
MutablePicoContainer slave = new DefaultPicoContainer();
recorder.replay(slave);
assertEquals("apple", slave.getComponentInstance("fruit"));
assertEquals("apple239", ((ThingThatTakesParamsInConstructor) slave.getComponentInstance("thing")).getValue());
// test that we can replay once more
MutablePicoContainer anotherSlave = new DefaultPicoContainer();
recorder.replay(anotherSlave);
assertEquals("apple", anotherSlave.getComponentInstance("fruit"));
assertEquals("apple239", ((ThingThatTakesParamsInConstructor) anotherSlave.getComponentInstance("thing")).getValue());
}