KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > script > groovy > buildernodes > TestAppendContainerNode


1 /*****************************************************************************
2  * Copyright (C) NanoContainer 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 Michael Rimov *
9  *****************************************************************************/

10
11 package org.nanocontainer.script.groovy.buildernodes;
12
13 import java.util.Collections JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import org.nanocontainer.NanoContainer;
16 import org.nanocontainer.reflection.DefaultNanoPicoContainer;
17 import org.nanocontainer.script.NanoContainerMarkupException;
18 import junit.framework.TestCase;
19
20 /**
21  * Tests node marking and exceptions
22  * @author Michael Rimov
23  */

24 public class TestAppendContainerNode extends TestCase {
25     private AppendContainerNode appendContainerNode = null;
26
27     protected void setUp() throws Exception JavaDoc {
28         super.setUp();
29         appendContainerNode = new AppendContainerNode();
30     }
31
32     protected void tearDown() throws Exception JavaDoc {
33         appendContainerNode = null;
34         super.tearDown();
35     }
36
37     public void testCreateNewNodeWithoutParameterThrowsException() {
38         try {
39             appendContainerNode.createNewNode(null, Collections.EMPTY_MAP);
40             fail("Should have thrown exception");
41         } catch (NanoContainerMarkupException ex) {
42             //ok
43
}
44     }
45
46     public void testCreateNodeWithParmeterReturnsParameter() throws NanoContainerMarkupException {
47         HashMap JavaDoc params = new HashMap JavaDoc();
48         NanoContainer nano = new DefaultNanoPicoContainer();
49         params.put(AppendContainerNode.CONTAINER, nano);
50         NanoContainer nano2 = (NanoContainer)appendContainerNode.createNewNode(null,params);
51         assertTrue(nano == nano2);
52     }
53
54     public void testCreateWithImproperTypeThrowsClassCastException() throws NanoContainerMarkupException {
55         HashMap JavaDoc params = new HashMap JavaDoc();
56         params.put(AppendContainerNode.CONTAINER, "This is a test");
57         try {
58             appendContainerNode.createNewNode(null, params);
59             fail("Should have thrown exception");
60         } catch (ClassCastException JavaDoc ex) {
61             //ok
62
}
63     }
64
65 }
66
Popular Tags