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.internal.util;
16:
17: import java.lang.reflect.Modifier;
18:
19: import org.apache.tapestry.MarkupWriter;
20: import org.apache.tapestry.internal.util.MethodInvocationBuilder;
21: import org.apache.tapestry.services.ClassTransformation;
22: import org.apache.tapestry.services.MethodSignature;
23: import org.apache.tapestry.test.TapestryTestCase;
24: import org.testng.annotations.Test;
25:
26: public class MethodInvocationBuilderTest extends TapestryTestCase {
27: private static final String LOCALE_CLASS_NAME = "java.util.Locale";
28:
29: private static final String MARKUP_WRITER_CLASS_NAME = MarkupWriter.class
30: .getName();
31:
32: @Test
33: public void known_parameter_type() {
34: ClassTransformation transformation = mockClassTransformation();
35:
36: replay();
37:
38: MethodSignature sig = new MethodSignature(Modifier.PUBLIC,
39: "void", "myMethod",
40: new String[] { MARKUP_WRITER_CLASS_NAME }, null);
41:
42: MethodInvocationBuilder invoker = new MethodInvocationBuilder();
43:
44: invoker.addParameter(MARKUP_WRITER_CLASS_NAME, "$1");
45:
46: assertEquals(
47: invoker.buildMethodInvocation(sig, transformation),
48: "myMethod($1)");
49:
50: verify();
51: }
52:
53: @Test
54: public void unknown_parameter_type() {
55: ClassTransformation transformation = mockClassTransformation();
56:
57: replay();
58:
59: MethodSignature sig = new MethodSignature(Modifier.PUBLIC,
60: "void", "myMethod",
61: new String[] { MARKUP_WRITER_CLASS_NAME }, null);
62:
63: MethodInvocationBuilder invoker = new MethodInvocationBuilder();
64:
65: assertEquals(
66: invoker.buildMethodInvocation(sig, transformation),
67: "myMethod(null)");
68:
69: verify();
70: }
71:
72: @Test
73: public void multiple_parameters_for_method() {
74: ClassTransformation transformation = mockClassTransformation();
75:
76: replay();
77:
78: MethodSignature sig = new MethodSignature(Modifier.PUBLIC,
79: "void", "myMethod", new String[] {
80: MARKUP_WRITER_CLASS_NAME, LOCALE_CLASS_NAME },
81: null);
82:
83: MethodInvocationBuilder invoker = new MethodInvocationBuilder();
84:
85: invoker.addParameter(MARKUP_WRITER_CLASS_NAME, "$1");
86: invoker.addParameter(LOCALE_CLASS_NAME, "$2");
87:
88: assertEquals(
89: invoker.buildMethodInvocation(sig, transformation),
90: "myMethod($1, $2)");
91:
92: verify();
93: }
94: }
|