001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.valid;
016    
017    import static org.easymock.EasyMock.checkOrder;
018    import static org.easymock.EasyMock.expect;
019    
020    import java.util.Locale;
021    
022    import org.apache.tapestry.IPage;
023    import org.apache.tapestry.form.IFormComponent;
024    import org.apache.tapestry.junit.TapestryTestCase;
025    
026    /**
027     * Base class for tests of different {@link org.apache.tapestry.valid.IValidator}implementations.
028     * 
029     * @author Howard M. Lewis Ship
030     * @since 4.0
031     */
032    public abstract class BaseValidatorTestCase extends TapestryTestCase
033    {
034    
035        protected IFormComponent newField()
036        {
037            return newMock(IFormComponent.class);
038        }
039    
040        protected IFormComponent newField(String displayName)
041        {
042            return newField(displayName, 1);
043        }
044    
045        protected IFormComponent newField(String displayName, int count)
046        {
047            return newField(displayName, Locale.ENGLISH, count);
048        }
049    
050        protected IFormComponent newField(String displayName, Locale locale)
051        {
052            return newField(displayName, locale, 1);
053        }
054    
055        protected IFormComponent newField(String displayName, Locale locale, int count)
056        {
057            IPage page = newPage(locale);
058            
059            IFormComponent component = newMock(IFormComponent.class);
060            
061            expect(component.getPage()).andReturn(page).anyTimes();
062            
063            expect(component.getDisplayName()).andReturn(displayName).anyTimes();
064    
065            return component;
066        }
067    
068        protected IPage newPage(Locale locale)
069        {
070            IPage page = newPage();
071            
072            checkOrder(page, false);
073            
074            expect(page.getLocale()).andReturn(locale).anyTimes();
075    
076            return page;
077        }
078    
079    }