DoubleRangeValidatorTest.java :  » Database-ORM » csvbeans » org » csvbeans » validators » Java Open Source

Java Open Source » Database ORM » csvbeans 
csvbeans » org » csvbeans » validators » DoubleRangeValidatorTest.java
/*
 * Copyright 2004-2006 Fouad HAMDI with the idea 
 * of SameLAN, S.L. Soluciones Tecnolgicas.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.csvbeans.validators;

import org.csvbeans.Property;
import org.csvbeans.exceptions.ValidationException;
import org.jmock.core.Constraint;

/**
 * Tests for the double range validator.
 * 
 * @author Fouad Hamdi
 * @since 0.7
 */
public class DoubleRangeValidatorTest extends ValidatorTestCase {
    private DoubleRangeValidator validator;
    
    protected void setUp() throws Exception {
      super.setUp();
        validator = new DoubleRangeValidator();
    }
    
    public void testMinimumValue() throws Exception {
        validator.addProperty(new Property("minimumValue", "22.22"));
        validator.validate("36.36");
        validator.validate("22.22");
        try {
          messageContainer.expects(once()).method("getMessage")
        .with(new Constraint[] {eq("value.number.minimum"), eq(new Object[] {new Double(22.21), new Double(22.22)})})
        .will(returnValue("errorMessage"));
          
            validator.validate("22.21");
            fail("An exception should have been thrown");
        } catch (ValidationException e) {
            assertTrue(true);
        }
    }
    
    public void testMaximumValue() throws Exception {
        validator.addProperty(new Property("maximumValue", "36.36"));
        validator.validate("36.36");
        validator.validate("22.22");
        try {
          messageContainer.expects(once()).method("getMessage")
        .with(new Constraint[] {eq("value.number.maximum"), eq(new Object[] {new Double(36.37), new Double(36.36)})})
        .will(returnValue("errorMessage"));
          
            validator.validate("36.37");
            fail("An exception should have been thrown");
        } catch (ValidationException e) {
            assertTrue(true);
        }
    }
    
    public void testMinimumMaximum() throws Exception {
        validator.addProperty(new Property("minimumValue", "22.22"));
        validator.addProperty(new Property("maximumValue", "10.10"));
        try {
          messageContainer.expects(once()).method("getMessage")
        .with(new Constraint[] {eq("value.minimum.maximum"), eq(new Object[] {new Double(22.22), new Double(10.1)})})
        .will(returnValue("errorMessage"));
          
            validator.validate("10.10");
            fail("An exception should have been thrown");
        } catch (ValidationException e) {
            assertTrue(true);
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.