/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.apache.bval.constraints;

import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import java.math.BigDecimal;

/**
 * DigitsConstraintValidator Tester.
 *
 * @author <Authors name>
 * @since <pre>02/03/2009</pre>
 * @version 1.0
 */
public class DigitsValidatorTest extends TestCase {
    public DigitsValidatorTest(String name) {
        super(name);
    }

    public void testValidateNumber() {
        DigitsValidatorForNumber validator = new DigitsValidatorForNumber();
        validator.setFractional(4);
        validator.setIntegral(2);
        BigDecimal val = new BigDecimal("100.12345");
        Assert.assertFalse(validator.isValid(val, null));
        val = new BigDecimal("99.1234");
        Assert.assertTrue(validator.isValid(val, null));
    }

    public void testValidateString() {
        DigitsValidatorForString validator = new DigitsValidatorForString();
        validator.setFractional(4);
        validator.setIntegral(2);
        String val = "100.12345";
        Assert.assertFalse(validator.isValid(val, null));
        val = "99.1234";
        Assert.assertTrue(validator.isValid(val, null));
    }

    public void testValidateNumber2() {
        DigitsValidatorForNumber validator = new DigitsValidatorForNumber();
        validator.setFractional(4);
        validator.setIntegral(2);
        Long val = new Long("100");
        Assert.assertFalse(validator.isValid(val, null));
        val = new Long("99");
        Assert.assertTrue(validator.isValid(val, null));
    }

    public void testValidateString2() {
        DigitsValidatorForString validator = new DigitsValidatorForString();
        validator.setFractional(0);
        validator.setIntegral(2);
        String val = "99.5";
        Assert.assertFalse(validator.isValid(val, null));
        val = "99";
        Assert.assertTrue(validator.isValid(val, null));
    }

    public static Test suite() {
        return new TestSuite(DigitsValidatorTest.class);
    }
}

@@ -1445,25 +1445,45 @@
     
-BigDecimal val = 
+Assert.assertFalse(validator.isValid(
 new 
@@ -1502,18 +1502,25 @@
 100.1234
-5
 %22
+), null)
 );%0A     
@@ -1563,59 +1563,278 @@
 lid(
-val, null));%0A        val = new BigDecimal(%2299.1234%22
+new BigDecimal(%2299.12345%22), null));%0A        Assert.assertTrue(validator.isValid(new BigDecimal(%2299.1234%22), null));%0A        Assert.assertFalse(validator.isValid(Double.valueOf(100.1234), null));%0A        Assert.assertFalse(validator.isValid(Double.valueOf(99.12345), null)
 );%0A 
@@ -1868,35 +1868,55 @@
 lidator.isValid(
-val
+Double.valueOf(99.1234)
 , null));%0A    %7D%0A

add a few additional digits tests