01: /* ====================================================================
02: The Jicarilla Software License
03:
04: Copyright (c) 2003 Leo Simons.
05: All rights reserved.
06:
07: Permission is hereby granted, free of charge, to any person obtaining
08: a copy of this software and associated documentation files (the
09: "Software"), to deal in the Software without restriction, including
10: without limitation the rights to use, copy, modify, merge, publish,
11: distribute, sublicense, and/or sell copies of the Software, and to
12: permit persons to whom the Software is furnished to do so, subject to
13: the following conditions:
14:
15: The above copyright notice and this permission notice shall be
16: included in all copies or substantial portions of the Software.
17:
18: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25: ==================================================================== */
26: package org.jicarilla.container.test.builder;
27:
28: import junit.framework.TestCase;
29: import org.jicarilla.container.Resolver;
30: import org.jicarilla.container.adapters.SingletonAdapter;
31: import org.jicarilla.container.builder.DefaultBuilder;
32: import org.jicarilla.container.builder.DefaultBuilder;
33: import org.jicarilla.container.factories.ManualFactory;
34: import org.jicarilla.container.selectors.ClassSelector;
35: import org.jicarilla.container.tck.components.interfaces.Homer;
36: import org.jicarilla.container.tck.components.interfaces.Lisa;
37: import org.jicarilla.container.tck.components.interfaces.Marge;
38: import org.jicarilla.container.tck.components.type3.rich.BartImpl;
39: import org.jicarilla.container.tck.components.type3.rich.HomerImpl;
40: import org.jicarilla.container.tck.components.type3.rich.LisaImpl;
41: import org.jicarilla.container.tck.components.type3.rich.MargeImpl;
42: import org.jicarilla.container.tck.components.type3.rich.YoungHomer;
43:
44: /**
45: *
46: *
47: * @author <a href="mail at leosimons dot com">Leo Simons</a>
48: * @version $Id: DefaultBuilderTestCase.java,v 1.7 2004/03/17 16:35:31 lsimons Exp $
49: */
50: public class DefaultBuilderTestCase extends TestCase {
51: public void testBasicUsage() throws Exception {
52: // this tests actually results in a 100% coverage. Remarkable...
53: // shows the robustness of the DefaultBuilder class I guess...very
54: // little excess fat there :-D
55: Resolver resolver = DefaultBuilder.newInstance().addComponent(
56: HomerImpl.class).addComponent(YoungHomer.class)
57:
58: .addComponent(new HomerImpl()).addComponent(new BartImpl())
59: .addComponent(
60: new ClassSelector(Marge.class),
61: new SingletonAdapter(new ManualFactory(
62: new MargeImpl()))).addComponent(
63: LisaImpl.class).create();
64:
65: Lisa lisa = (Lisa) resolver.get(Lisa.class);
66: Homer homer = (Homer) resolver.get(Homer.class);
67: Marge marge = (Marge) resolver.get(Marge.class);
68: lisa.actSmart();
69: homer.burp();
70: marge.frown();
71: }
72:
73: public void testNullProviderThrowsException() throws Exception {
74: try {
75: DefaultBuilder.newInstance().addComponent(null);
76: fail("Expected an exception!");
77: } catch (AssertionError ae) {
78: }
79:
80: }
81: }
|