KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > binding > TestBindingUtils


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.binding;
16
17 import org.apache.hivemind.test.HiveMindTestCase;
18 import org.apache.tapestry.spec.IComponentSpecification;
19 import org.apache.tapestry.spec.IParameterSpecification;
20 import org.easymock.MockControl;
21
22 /**
23  * Tests for {@link org.apache.tapestry.binding.BindingUtils}.
24  *
25  * @author Howard M. Lewis Ship
26  * @since 4.0
27  */

28 public class TestBindingUtils extends HiveMindTestCase
29 {
30     private IComponentSpecification newSpec(String JavaDoc name, IParameterSpecification pspec)
31     {
32         MockControl control = newControl(IComponentSpecification.class);
33         IComponentSpecification spec = (IComponentSpecification) control.getMock();
34
35         spec.getParameter(name);
36         control.setReturnValue(pspec);
37
38         return spec;
39     }
40
41     private IParameterSpecification newParameterSpec(String JavaDoc defaultBindingType)
42     {
43         MockControl control = newControl(IParameterSpecification.class);
44         IParameterSpecification pspec = (IParameterSpecification) control.getMock();
45
46         pspec.getDefaultBindingType();
47         control.setReturnValue(defaultBindingType);
48
49         return pspec;
50     }
51
52     public void testInformalParameter()
53     {
54         IComponentSpecification spec = newSpec("informal", null);
55
56         replayControls();
57
58         assertEquals("fred", BindingUtils.getDefaultBindingType(spec, "informal", "fred"));
59
60         verifyControls();
61     }
62
63     public void testFormalParameterWithDefault()
64     {
65         IParameterSpecification pspec = newParameterSpec("barney");
66         IComponentSpecification spec = newSpec("formal", pspec);
67
68         replayControls();
69
70         assertEquals("barney", BindingUtils.getDefaultBindingType(spec, "formal", "fred"));
71
72         verifyControls();
73     }
74
75     public void testFormalParameterWithoutDefault()
76     {
77         IParameterSpecification pspec = newParameterSpec(null);
78         IComponentSpecification spec = newSpec("formal", pspec);
79
80         replayControls();
81
82         assertEquals("fred", BindingUtils.getDefaultBindingType(spec, "formal", "fred"));
83
84         verifyControls();
85     }
86 }
Popular Tags