01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Original code by Michael Rimov *
09: *****************************************************************************/package org.nanocontainer.script.groovy.buildernodes;
10:
11: import java.util.Collections;
12: import java.util.HashMap;
13: import org.nanocontainer.NanoContainer;
14: import org.nanocontainer.reflection.DefaultNanoPicoContainer;
15: import org.nanocontainer.script.NanoContainerMarkupException;
16: import junit.framework.TestCase;
17:
18: /**
19: * Tests node marking and exceptions
20: * @author Michael Rimov
21: */
22: public class TestAppendContainerNode extends TestCase {
23: private AppendContainerNode appendContainerNode = null;
24:
25: protected void setUp() throws Exception {
26: super .setUp();
27: appendContainerNode = new AppendContainerNode();
28: }
29:
30: protected void tearDown() throws Exception {
31: appendContainerNode = null;
32: super .tearDown();
33: }
34:
35: public void testCreateNewNodeWithoutParameterThrowsException() {
36: try {
37: appendContainerNode.createNewNode(null,
38: Collections.EMPTY_MAP);
39: fail("Should have thrown exception");
40: } catch (NanoContainerMarkupException ex) {
41: //ok
42: }
43: }
44:
45: public void testCreateNodeWithParmeterReturnsParameter()
46: throws NanoContainerMarkupException {
47: HashMap params = new HashMap();
48: NanoContainer nano = new DefaultNanoPicoContainer();
49: params.put(AppendContainerNode.CONTAINER, nano);
50: NanoContainer nano2 = (NanoContainer) appendContainerNode
51: .createNewNode(null, params);
52: assertTrue(nano == nano2);
53: }
54:
55: public void testCreateWithImproperTypeThrowsClassCastException()
56: throws NanoContainerMarkupException {
57: HashMap params = new HashMap();
58: params.put(AppendContainerNode.CONTAINER, "This is a test");
59: try {
60: appendContainerNode.createNewNode(null, params);
61: fail("Should have thrown exception");
62: } catch (ClassCastException ex) {
63: //ok
64: }
65: }
66:
67: }
|