incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r931103 - in /incubator/bval/trunk/bval-jsr303/src: main/java/org/apache/bval/constraints/ test/java/org/apache/bval/constraints/
Date Tue, 06 Apr 2010 11:55:57 GMT
Author: romanstumm
Date: Tue Apr  6 11:55:56 2010
New Revision: 931103

URL: http://svn.apache.org/viewvc?rev=931103&view=rev
Log:
BVAL-15 merged patches for " @Min and @Max fail with very high values of long"

Added:
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java
Modified:
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java?rev=931103&r1=931102&r2=931103&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
Tue Apr  6 11:55:56 2010
@@ -49,5 +49,5 @@ public class DecimalMaxValidatorForNumbe
         } else {
             return (new BigDecimal(value.doubleValue()).compareTo(maxValue)) != 1;
         }
-    }
+    }           
 }

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java?rev=931103&r1=931102&r2=931103&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java
Tue Apr  6 11:55:56 2010
@@ -44,7 +44,7 @@ public class MaxValidatorForNumber imple
         } else if (value instanceof BigInteger) {
             return ((BigInteger) value).compareTo(BigInteger.valueOf(max)) != 1;
         } else {
-            return value.doubleValue() <= max;
+            return value.longValue() <= max;
         }
     }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java?rev=931103&r1=931102&r2=931103&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java
Tue Apr  6 11:55:56 2010
@@ -43,7 +43,7 @@ public class MinValidatorForNumber imple
         } else if (value instanceof BigInteger) {
             return ((BigInteger) value).compareTo(BigInteger.valueOf(minValue)) != -1;
         } else {
-            return value.doubleValue() >= minValue;
+            return value.longValue() >= minValue;
         }
 
     }

Added: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java?rev=931103&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java
(added)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java
Tue Apr  6 11:55:56 2010
@@ -0,0 +1,65 @@
+/*
+ * 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.TestCase;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+import java.util.Set;
+
+/**
+ * Description: <br>
+ * User: roman.stumm<br>
+ * Date: 06.04.2010<br>
+ * Time: 13:45:09<br>
+ */
+public class DecimalMinMaxValidatorsTest extends TestCase {
+
+  @DecimalMin("922392239223.06")
+  public double dmin;
+  @DecimalMax("922392239223.09")
+  public double dmax;
+
+
+  public void testDecimalMinValue() {
+    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+
+    this.dmin = 922392239223.05;
+    this.dmax = 922392239223.08;
+
+    Set<ConstraintViolation<DecimalMinMaxValidatorsTest>> res = v.validate(this);
+    assertFalse("Min validation failed", res.isEmpty());
+  }
+
+  public void testDecimalMaxValue() {
+    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+
+    this.dmin = Double.MAX_VALUE;
+    this.dmax = 922392239223.1;
+
+    Set<ConstraintViolation<DecimalMinMaxValidatorsTest>> res = v.validate(this);
+    assertFalse("Max validation failed", res.isEmpty());
+  }
+
+
+}

Added: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java?rev=931103&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java
(added)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java
Tue Apr  6 11:55:56 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.TestCase;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import java.util.Set;
+
+
+/**
+ * Check correct behaviour of {@link MinValidatorForNumber} and
+ * {@link MaxValidatorForNumber} on boundary values.
+ * <p/>
+ * The chosen numbers: 9223372036854775806l and 9223372036854775807l cast to
+ * the same double value.
+ *
+ * @author Carlos Vara
+ */
+public class MinMaxValidatorsForNumberTest extends TestCase {
+
+  @Min(value = 9223372036854775807l)
+  public long min;
+
+  @Max(value = 9223372036854775806l)
+  public long max;
+
+
+  public void testMinBoundaryValue() {
+    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+
+    this.min = 9223372036854775806l;
+    this.max = 0l;
+
+    // Current min value is smaller, should fail, but it doesn't
+    Set<ConstraintViolation<MinMaxValidatorsForNumberTest>> res = v.validate(this);
+    assertFalse("Min validation failed", res.isEmpty());
+  }
+
+  public void testMaxBoundaryValue() {
+    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+
+    this.min = Long.MAX_VALUE;
+    this.max = 9223372036854775807l;
+
+    // Current max value is bigger, should fail, but it doesn't
+    Set<ConstraintViolation<MinMaxValidatorsForNumberTest>> res = v.validate(this);
+    assertFalse("Max validation failed", res.isEmpty());
+  }
+
+
+}



Mime
View raw message