KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > annotations > TestInjectObjectAnnotationWorker


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.annotations;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import org.apache.tapestry.enhance.EnhancementOperation;
20 import org.apache.tapestry.enhance.InjectObjectWorker;
21 import org.apache.tapestry.services.InjectedValueProvider;
22 import org.apache.tapestry.spec.IComponentSpecification;
23 import org.easymock.MockControl;
24
25 /**
26  * Tests for {@link org.apache.tapestry.annotations.InjectObjectAnnotationWorker}.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31
32 public class TestInjectObjectAnnotationWorker extends BaseAnnotationTestCase
33 {
34     public void testDefault()
35     {
36         InjectObjectAnnotationWorker worker = new InjectObjectAnnotationWorker();
37
38         assertNotNull(worker._delegate);
39     }
40
41     public void testDelegation()
42     {
43         EnhancementOperation op = newOp();
44         IComponentSpecification spec = newSpec();
45
46         InjectObjectWorker delegate = (InjectObjectWorker) newMock(InjectObjectWorker.class);
47
48         InjectedValueProvider provider = (InjectedValueProvider) newMock(InjectedValueProvider.class);
49
50         delegate.setProvider(provider);
51
52         replayControls();
53
54         InjectObjectAnnotationWorker worker = new InjectObjectAnnotationWorker(delegate);
55         worker.setProvider(provider);
56
57         verifyControls();
58
59         Method JavaDoc m = findMethod(AnnotatedPage.class, "getInjectedObject");
60
61         delegate.injectObject(op, "barney", "injectedObject", null);
62
63         replayControls();
64
65         worker.performEnhancement(op, spec, m, null);
66
67         verifyControls();
68     }
69
70 }
71
Popular Tags