KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > valid > 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.valid;
16
17 import java.util.Locale JavaDoc;
18
19 import org.apache.tapestry.IPage;
20 import org.apache.tapestry.form.IFormComponent;
21 import org.apache.tapestry.junit.TapestryTestCase;
22 import org.easymock.MockControl;
23
24 /**
25  * Base class for tests of different {@link org.apache.tapestry.valid.IValidator}implementations.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public abstract class BaseValidatorTestCase extends TapestryTestCase
31 {
32
33     protected IFormComponent newField()
34     {
35         return (IFormComponent) newMock(IFormComponent.class);
36     }
37
38     protected IFormComponent newField(String JavaDoc displayName)
39     {
40         return newField(displayName, 1);
41     }
42
43     protected IFormComponent newField(String JavaDoc displayName, int count)
44     {
45         return newField(displayName, Locale.ENGLISH, count);
46     }
47
48     protected IFormComponent newField(String JavaDoc displayName, Locale JavaDoc locale)
49     {
50         return newField(displayName, locale, 1);
51     }
52
53     protected IFormComponent newField(String JavaDoc displayName, Locale JavaDoc locale, int count)
54     {
55         IPage page = newPage(locale, count);
56
57         MockControl control = newControl(IFormComponent.class);
58         IFormComponent component = (IFormComponent) control.getMock();
59
60         for (int i = 0; i < count; i++)
61         {
62             component.getPage();
63             control.setReturnValue(page);
64
65             component.getDisplayName();
66             control.setReturnValue(displayName);
67         }
68
69         return component;
70     }
71
72     protected IPage newPage(Locale JavaDoc locale)
73     {
74         return newPage(locale, 1);
75     }
76
77     protected IPage newPage(Locale JavaDoc locale, int count)
78     {
79         MockControl pagec = newControl(IPage.class);
80         IPage page = (IPage) pagec.getMock();
81
82         page.getLocale();
83         pagec.setReturnValue(locale, count);
84
85         return page;
86     }
87
88 }
Popular Tags