KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > validator > BaseValidatorTestCase


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.validator;
16
17 import org.apache.tapestry.components.BaseComponentTestCase;
18 import org.apache.tapestry.form.FormComponentContributorContext;
19 import org.apache.tapestry.form.IFormComponent;
20 import org.apache.tapestry.form.ValidationMessages;
21 import org.easymock.MockControl;
22
23 /**
24  * Base class for writing {@link org.apache.tapestry.form.validator.Validator} tests.
25  *
26  * @author Howard Lewis Ship
27  * @since 4.0
28  */

29 public abstract class BaseValidatorTestCase extends BaseComponentTestCase
30 {
31     protected IFormComponent newField(String JavaDoc displayName)
32     {
33         MockControl control = newControl(IFormComponent.class);
34         IFormComponent field = (IFormComponent) control.getMock();
35
36         field.getDisplayName();
37         control.setReturnValue(displayName);
38
39         return field;
40     }
41
42     protected IFormComponent newField()
43     {
44         return (IFormComponent) newMock(IFormComponent.class);
45     }
46
47     protected ValidationMessages newMessages()
48     {
49         return (ValidationMessages) newMock(ValidationMessages.class);
50     }
51
52     protected ValidationMessages newMessages(String JavaDoc messageOverride, String JavaDoc messageKey, Object JavaDoc[] parameters, String JavaDoc result)
53     {
54         MockControl control = newControl(ValidationMessages.class);
55         ValidationMessages messages = (ValidationMessages) control.getMock();
56     
57         trainFormatMessage(control, messages, messageOverride, messageKey, parameters, result);
58     
59         return messages;
60     }
61
62     protected void trainFormatMessage(MockControl control, ValidationMessages messages, String JavaDoc messageOverride, String JavaDoc messageKey, Object JavaDoc[] parameters, String JavaDoc result)
63     {
64         messages.formatValidationMessage(messageOverride, messageKey, parameters);
65         control.setMatcher(MockControl.ARRAY_MATCHER);
66         control.setReturnValue(result);
67     }
68
69     protected FormComponentContributorContext newContext()
70     {
71         return (FormComponentContributorContext) newMock(FormComponentContributorContext.class);
72     }
73
74 }
75
Popular Tags