KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tests > jfun > yan > tck > BaseLazyInstantiationTestCase


1 /*****************************************************************************
2  * Copyright (C) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by *
9  *****************************************************************************/

10 package tests.jfun.yan.tck;
11
12 import junit.framework.TestCase;
13 import junit.framework.TestSuite;
14 import jfun.yan.*;
15 import jfun.yan.containers.DefaultContainer;
16
17 /**
18  * @author Aslak Hellesøy
19  * @version $Revision: 1.2 $
20  */

21 public class BaseLazyInstantiationTestCase extends TestCase {
22   public static void main(String JavaDoc[] args){
23     tests.jfun.yan.Utils.runTest(suite());
24   }
25   private static TestSuite suite(){
26     return new TestSuite(BaseLazyInstantiationTestCase.class);
27   }
28     protected Container createPicoContainer(){return new DefaultContainer();}
29
30     public static class Kilroy {
31         public Kilroy(Havana havana) {
32             havana.graffiti("Kilroy was here");
33         }
34     }
35
36     public static class Havana {
37         public String JavaDoc paint = "Clean wall";
38
39         public void graffiti(String JavaDoc paint) {
40             this.paint = paint;
41         }
42     }
43
44     public void testLazyInstantiation(){
45         Container pico = createPicoContainer();
46
47         pico.registerConstructor(Kilroy.class);
48         pico.registerConstructor(Havana.class);
49         pico.verify();
50         assertSame(pico.getInstance(Havana.class), pico.getInstance(Havana.class));
51         assertNotNull(pico.getInstance(Havana.class));
52         assertEquals("Clean wall", ((Havana) pico.getInstance(Havana.class)).paint);
53         assertNotNull(pico.getInstance(Kilroy.class));
54         assertEquals("Kilroy was here", ((Havana) pico.getInstance(Havana.class)).paint);
55     }
56 }
57
Popular Tags