KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > BaseFormComponentTest


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.form;
16
17 import org.apache.tapestry.IActionListener;
18 import org.apache.tapestry.IBinding;
19 import org.apache.tapestry.IComponent;
20 import org.apache.tapestry.IForm;
21 import org.apache.tapestry.IMarkupWriter;
22 import org.apache.tapestry.IRequestCycle;
23 import org.apache.tapestry.TapestryUtils;
24 import org.apache.tapestry.components.BaseComponentTestCase;
25 import org.apache.tapestry.valid.IValidationDelegate;
26 import org.easymock.MockControl;
27
28 /**
29  * Base class for tests of implementations of {@link org.apache.tapestry.form.IFormComponent}.
30  *
31  * @author Howard M. Lewis Ship
32  * @since 4.0
33  */

34 public abstract class BaseFormComponentTest extends BaseComponentTestCase
35 {
36
37     protected IValidationDelegate newDelegate()
38     {
39         return (IValidationDelegate) newMock(IValidationDelegate.class);
40     }
41
42     protected void trainIsInError(MockControl control, IValidationDelegate delegate,
43             boolean isInError)
44     {
45         delegate.isInError();
46         control.setReturnValue(isInError);
47     }
48
49     protected IForm newForm()
50     {
51         return (IForm) newMock(IForm.class);
52     }
53
54     protected void trainGetForm(MockControl control, IRequestCycle cycle, IForm form)
55     {
56         cycle.getAttribute(TapestryUtils.FORM_ATTRIBUTE);
57         control.setReturnValue(form);
58     }
59
60     protected void trainGetDelegate(MockControl control, IForm form, IValidationDelegate delegate)
61     {
62         form.getDelegate();
63         control.setReturnValue(delegate);
64     }
65
66     protected void trainGetParameter(MockControl control, IRequestCycle cycle,
67             String JavaDoc parameterName, String JavaDoc parameterValue)
68     {
69         cycle.getParameter(parameterName);
70         control.setReturnValue(parameterValue);
71     }
72
73     protected void trainWasPrerendered(MockControl control, IForm form, IMarkupWriter writer,
74             IComponent component, boolean wasPrerendered)
75     {
76         form.wasPrerendered(writer, component);
77         control.setReturnValue(wasPrerendered);
78     }
79
80     protected void trainIsRewinding(MockControl control, IForm form, boolean isRewinding)
81     {
82         form.isRewinding();
83         control.setReturnValue(isRewinding);
84     }
85
86     protected void trainGetElementId(MockControl control, IForm form, IFormComponent component,
87             String JavaDoc name)
88     {
89         form.getElementId(component);
90         component.setName(name);
91         control.setReturnValue(name);
92     }
93
94     protected IBinding newBinding()
95     {
96         return (IBinding) newMock(IBinding.class);
97     }
98
99     protected IActionListener newListener()
100     {
101         return (IActionListener) newMock(IActionListener.class);
102     }
103 }
104
Popular Tags