01: // Copyright 2006 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.services;
16:
17: import java.lang.reflect.Method;
18:
19: import org.apache.tapestry.ioc.internal.IOCInternalTestCase;
20: import org.apache.tapestry.ioc.services.MethodSignature;
21: import org.testng.annotations.Test;
22:
23: public class FilterMethodAnalyzerTest extends IOCInternalTestCase {
24: private MethodSignature find(Class target, String name) {
25: Method method = findMethod(target, name);
26:
27: return new MethodSignature(method);
28: }
29:
30: private void assertPosition(String methodName, int expected) {
31: FilterMethodAnalyzer a = new FilterMethodAnalyzer(
32: SampleService.class);
33:
34: MethodSignature ms = find(SampleService.class, methodName);
35: MethodSignature fms = find(SampleFilter.class, methodName);
36:
37: assertEquals(expected, a.findServiceInterfacePosition(ms, fms));
38: }
39:
40: private void assertMismatch(String methodName) {
41: assertPosition(methodName, -1);
42: }
43:
44: @Test
45: public void simple_match() {
46: assertPosition("simpleMatch", 0);
47: }
48:
49: @Test
50: public void mismatched_parameter_count() {
51: assertMismatch("mismatchParameterCount");
52: }
53:
54: @Test
55: public void mismatch_on_method_return_type() {
56: assertMismatch("mismatchReturnType");
57: }
58:
59: @Test
60: public void service_interface_not_in_filter_method_signature() {
61: assertMismatch("missingServiceInterface");
62: }
63:
64: @Test
65: public void match_with_multiple_parameters() {
66: assertPosition("complexMatch", 2);
67: }
68: }
|