01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc.internal;
16:
17: import org.apache.commons.logging.Log;
18: import org.apache.tapestry.ioc.Configuration;
19: import org.apache.tapestry.ioc.def.ContributionDef;
20: import org.testng.annotations.Test;
21:
22: public class ValidatingConfigurationWrapperTest extends
23: IOCInternalTestCase {
24: @SuppressWarnings("unchecked")
25: @Test
26: public void valid_contribution() {
27: ContributionDef def = mockContributionDef();
28: Log log = mockLog();
29: Configuration configuration = mockConfiguration();
30: Runnable value = mockRunnable();
31:
32: configuration.add(value);
33:
34: replay();
35:
36: Configuration wrapper = new ValidatingConfigurationWrapper(
37: "foo.Bar", log, Runnable.class, def, configuration);
38:
39: wrapper.add(value);
40:
41: verify();
42: }
43:
44: @SuppressWarnings("unchecked")
45: @Test
46: public void null_contribution() {
47: Log log = mockLog();
48: Configuration configuration = mockConfiguration();
49: ContributionDef def = new ContributionDefImpl("Bar",
50: findMethod("contributeUnorderedNull"),
51: getClassFactory());
52:
53: log.warn(IOCMessages.contributionWasNull("Bar", def));
54:
55: replay();
56:
57: Configuration wrapper = new ValidatingConfigurationWrapper(
58: "Bar", log, Runnable.class, def, configuration);
59:
60: wrapper.add(null);
61:
62: verify();
63: }
64:
65: @SuppressWarnings("unchecked")
66: @Test
67: public void wrong_type_of_contribution() {
68: Log log = mockLog();
69: Configuration configuration = mockConfiguration();
70: ContributionDef def = new ContributionDefImpl("Bar",
71: findMethod("contributeUnorderedNull"),
72: getClassFactory());
73:
74: log.warn(IOCMessages.contributionWrongValueType("Bar", def,
75: String.class, Runnable.class));
76:
77: replay();
78:
79: Configuration wrapper = new ValidatingConfigurationWrapper(
80: "Bar", log, Runnable.class, def, configuration);
81:
82: wrapper.add("runnable");
83:
84: verify();
85: }
86:
87: // Just a placeholder to give the errors something to report about
88:
89: public void contributeUnorderedNull() {
90:
91: }
92:
93: public void contributeWrongType() {
94:
95: }
96:
97: }
|