/*****************************************************************************
* Copyright (C) PicoContainer Organization. All rights reserved. *
* ------------------------------------------------------------------------- *
* The software in this package is published under the terms of the BSD *
* style license a copy of which has been included with this distribution in *
* the LICENSE.txt file. *
* *
* Original code by *
*****************************************************************************/
package tests.jfun.yan.tck;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import jfun.yan.*;
import jfun.yan.containers.DefaultContainer;
/**
* @author Aslak Hellesøy
* @version $Revision: 1.2 $
*/
public class BaseLazyInstantiationTestCase extends TestCase {
public static void main(String[] args){
tests.jfun.yan.Utils.runTest(suite());
}
private static TestSuite suite(){
return new TestSuite(BaseLazyInstantiationTestCase.class);
}
protected Container createPicoContainer(){return new DefaultContainer();}
public static class Kilroy {
public Kilroy(Havana havana) {
havana.graffiti("Kilroy was here");
}
}
public static class Havana {
public String paint = "Clean wall";
public void graffiti(String paint) {
this.paint = paint;
}
}
public void testLazyInstantiation(){
Container pico = createPicoContainer();
pico.registerConstructor(Kilroy.class);
pico.registerConstructor(Havana.class);
pico.verify();
assertSame(pico.getInstance(Havana.class), pico.getInstance(Havana.class));
assertNotNull(pico.getInstance(Havana.class));
assertEquals("Clean wall", ((Havana) pico.getInstance(Havana.class)).paint);
assertNotNull(pico.getInstance(Kilroy.class));
assertEquals("Kilroy was here", ((Havana) pico.getInstance(Havana.class)).paint);
}
}