KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > enhance > TestInjectListenerRegistrationWorker


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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.enhance;
16
17 import org.apache.hivemind.test.HiveMindTestCase;
18 import org.apache.tapestry.IComponent;
19 import org.apache.tapestry.spec.IComponentSpecification;
20 import org.easymock.MockControl;
21
22 /**
23  * Tests for {@link TestInjectListenerRegistrationWorker}.
24  *
25  * @author Howard M. Lewis Ship
26  * @since 4.0
27  */

28 public class TestInjectListenerRegistrationWorker extends HiveMindTestCase
29 {
30     private IComponentSpecification newSpec()
31     {
32         return (IComponentSpecification) newMock(IComponentSpecification.class);
33     }
34
35     public void testNonMatch()
36     {
37         MockControl control = newControl(EnhancementOperation.class);
38         EnhancementOperation op = (EnhancementOperation) control.getMock();
39
40         IComponentSpecification spec = newSpec();
41
42         op.implementsInterface(Runnable JavaDoc.class);
43         control.setReturnValue(false);
44
45         replayControls();
46
47         InjectListenerRegistrationWorker w = new InjectListenerRegistrationWorker();
48         w.setListenerInterface(Runnable JavaDoc.class);
49
50         w.performEnhancement(op, spec);
51
52         verifyControls();
53     }
54
55     public void testMatch()
56     {
57         MockControl control = newControl(EnhancementOperation.class);
58         EnhancementOperation op = (EnhancementOperation) control.getMock();
59
60         IComponentSpecification spec = newSpec();
61
62         op.implementsInterface(IComponent.class);
63         control.setReturnValue(true);
64
65         op.extendMethodImplementation(
66                 IComponent.class,
67                 EnhanceUtils.FINISH_LOAD_SIGNATURE,
68                 "getPage().addThisComponentAsListener(this);");
69
70         replayControls();
71
72         InjectListenerRegistrationWorker w = new InjectListenerRegistrationWorker();
73         w.setListenerInterface(IComponent.class);
74         w.setRegisterMethodName("addThisComponentAsListener");
75
76         w.performEnhancement(op, spec);
77
78         verifyControls();
79     }
80
81 }
Popular Tags