Public: Add default validators for the standard constraints.
Include super source version of the Pattern constraint
that does not reference java.util.regex.Pattern
Review at http://gwt-code-reviews.appspot.com/735801
Review by: rjrjr@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8491 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/build.xml b/user/build.xml
index 964f1bb..eb8e016 100755
--- a/user/build.xml
+++ b/user/build.xml
@@ -109,7 +109,6 @@
<pathelement location="${gwt.tools.lib}/junit/junit-3.8.1.jar" />
<pathelement location="${gwt.tools.lib}/selenium/selenium-java-client-driver.jar" />
<pathelement location="${gwt.tools}/redist/json/r2_20080312/json-1.5.jar" />
- <pathelement location="${gwt.tools.lib}/javax/validation/validation-api-1.0.0.GA.jar" />
<path refid="test.extraclasspath" />
</classpath>
</gwt.javac>
@@ -130,7 +129,9 @@
<target name="checkstyle" description="Static analysis of source">
<gwt.checkstyle>
- <fileset dir="src" />
+ <fileset dir="src" >
+ <exclude name="javax/validation/super/javax/validation/constraints/Pattern.java"/>
+ </fileset>
<fileset dir="super/com/google/gwt/emul" />
<fileset dir="super/com/google/gwt/junit/translatable" />
</gwt.checkstyle>
diff --git a/user/src/com/google/gwt/validation/Validation.gwt.xml b/user/src/com/google/gwt/validation/Validation.gwt.xml
index 3daa6e3..6314a0b 100644
--- a/user/src/com/google/gwt/validation/Validation.gwt.xml
+++ b/user/src/com/google/gwt/validation/Validation.gwt.xml
@@ -17,6 +17,7 @@
-->
<module>
<inherits name="com.google.gwt.user.User"/>
+ <inherits name="com.google.gwt.regexp.RegExp"/>
<inherits name="javax.validation.Validation"/>
<source path="client"/>
</module>
diff --git a/user/src/com/google/gwt/validation/client/constraints/AbstractDecimalMaxValidator.java b/user/src/com/google/gwt/validation/client/constraints/AbstractDecimalMaxValidator.java
new file mode 100644
index 0000000..d1e2733
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AbstractDecimalMaxValidator.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.DecimalMax;
+
+/**
+ * Abstract {@link DecimalMax} constraint validator implementation for a
+ * <code>T</code>.
+ *
+ * @param <T> the type of object to validate
+ */
+public abstract class AbstractDecimalMaxValidator<T> implements
+ ConstraintValidator<DecimalMax, T> {
+
+ private BigDecimal max;
+
+ public AbstractDecimalMaxValidator() {
+ super();
+ }
+
+ @Override
+ public final void initialize(DecimalMax constraintAnnotation) {
+ try {
+ max = new BigDecimal(constraintAnnotation.value());
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(constraintAnnotation.value()
+ + " does not represent a valid BigDecimal format", e);
+ }
+ }
+
+ protected final boolean isValid(BigDecimal bigValue) {
+ return max.compareTo(bigValue) >= 0;
+ }
+}
\ No newline at end of file
diff --git a/user/src/com/google/gwt/validation/client/constraints/AbstractDecimalMinValidator.java b/user/src/com/google/gwt/validation/client/constraints/AbstractDecimalMinValidator.java
new file mode 100644
index 0000000..6f1d949
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AbstractDecimalMinValidator.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.DecimalMin;
+
+/**
+ * Abstract {@link DecimalMin} constraint validator implementation for a
+ * <code>T</code>.
+ *
+ * @param <T> the type of object to validate
+ */
+public abstract class AbstractDecimalMinValidator<T> implements
+ ConstraintValidator<DecimalMin, T> {
+
+ private BigDecimal min;
+
+ @Override
+ public final void initialize(DecimalMin constraintAnnotation) {
+ try {
+ min = new BigDecimal(constraintAnnotation.value());
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(constraintAnnotation.value()
+ + " does not represent a valid BigDecimal format", e);
+ }
+ }
+
+ protected final boolean isValid(BigDecimal bigValue) {
+ return min.compareTo(bigValue) <= 0;
+ }
+}
\ No newline at end of file
diff --git a/user/src/com/google/gwt/validation/client/constraints/AbstractDigitsValidator.java b/user/src/com/google/gwt/validation/client/constraints/AbstractDigitsValidator.java
new file mode 100644
index 0000000..0607706
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AbstractDigitsValidator.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.Digits;
+
+/**
+ * Abstract {@link Digits} constraint validator implementation for a
+ * <code>T</code>.
+ *
+ * @param <T> the type of object to validate
+ */
+public abstract class AbstractDigitsValidator<T> implements
+ ConstraintValidator<Digits, T> {
+
+ private int fraction;
+ private int integer;
+
+ @Override
+ public final void initialize(Digits constraintAnnotation) {
+ if (!(constraintAnnotation.fraction() >= 0)) {
+ throw new IllegalArgumentException(
+ "@Digits.fraction must be a nonnegative nubmer");
+ }
+ if (!(constraintAnnotation.integer() >= 0)) {
+ throw new IllegalArgumentException(
+ "@Digits.integer must be a nonnegative nubmer");
+ }
+ fraction = constraintAnnotation.fraction();
+ integer = constraintAnnotation.integer();
+ }
+
+ protected final boolean isValid(BigDecimal bigValue) {
+ int integerLength = bigValue.precision() - bigValue.scale();
+ if (integerLength > integer) {
+ return false;
+ }
+ int fractionalLength = bigValue.scale() < 0 ? 0 : bigValue.scale();
+ return fractionalLength <= fraction;
+ }
+}
\ No newline at end of file
diff --git a/user/src/com/google/gwt/validation/client/constraints/AbstractMaxValidator.java b/user/src/com/google/gwt/validation/client/constraints/AbstractMaxValidator.java
new file mode 100644
index 0000000..c4e3ce1
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AbstractMaxValidator.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.Max;
+
+/**
+ *
+ * @param <T> the type of object to validate
+ */
+public abstract class AbstractMaxValidator<T> implements
+ ConstraintValidator<Max, T> {
+
+ private long max;
+
+ @Override
+ public final void initialize(Max constraintAnnotation) {
+ max = constraintAnnotation.value();
+ }
+
+ protected final boolean isValid(Number value) {
+ if (value instanceof BigDecimal) {
+ return ((BigDecimal) value).compareTo(BigDecimal.valueOf(max)) <= 0;
+ } else if (value instanceof BigInteger) {
+ return ((BigInteger) value).compareTo(BigInteger.valueOf(max)) <= 0;
+ } else {
+ return value.longValue() <= max;
+ }
+ }
+}
\ No newline at end of file
diff --git a/user/src/com/google/gwt/validation/client/constraints/AbstractMinValidator.java b/user/src/com/google/gwt/validation/client/constraints/AbstractMinValidator.java
new file mode 100644
index 0000000..3d518d6
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AbstractMinValidator.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.Min;
+
+/**
+ * Abstract {@link Min} constraint validator implementation for a <code>T</code>
+ * .
+ *
+ * @param <T> the type of object to validate
+ */
+public abstract class AbstractMinValidator<T> implements
+ ConstraintValidator<Min, T> {
+
+ private long min;
+
+ @Override
+ public final void initialize(Min constraintAnnotation) {
+ min = constraintAnnotation.value();
+ }
+
+ protected final boolean isValid(Number value) {
+ if (value instanceof BigDecimal) {
+ return ((BigDecimal) value).compareTo(BigDecimal.valueOf(min)) >= 0;
+ } else if (value instanceof BigInteger) {
+ return ((BigInteger) value).compareTo(BigInteger.valueOf(min)) >= 0;
+ } else {
+ return value.longValue() >= min;
+ }
+ }
+}
\ No newline at end of file
diff --git a/user/src/com/google/gwt/validation/client/constraints/AbstractSizeValidator.java b/user/src/com/google/gwt/validation/client/constraints/AbstractSizeValidator.java
new file mode 100644
index 0000000..43d38b5
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AbstractSizeValidator.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.Size;
+
+/**
+ * Abstract {@link Size} constraint validator implementation.
+ *
+ * @param <T>
+ */
+public abstract class AbstractSizeValidator<T> implements
+ ConstraintValidator<Size, T> {
+
+ private int min;
+ private int max;
+
+ public AbstractSizeValidator() {
+ super();
+ }
+
+ public final void initialize(Size annotation) {
+ if (!(annotation.min() >= 0)) {
+ throw new IllegalArgumentException(
+ "@Size.min must be a nonnegative nubmer");
+ }
+ if (!(annotation.max() >= 0)) {
+ throw new IllegalArgumentException(
+ "@Size.max must be a nonnegative nubmer");
+ }
+ if (!(annotation.min() <= annotation.max())) {
+ throw new IllegalArgumentException(
+ "@Size.min must be less than or equal to @Size.max");
+ }
+ min = annotation.min();
+ max = annotation.max();
+ }
+
+ protected final boolean isLengthValid(int length) {
+ return min <= length && length <= max;
+ }
+}
\ No newline at end of file
diff --git a/user/src/com/google/gwt/validation/client/constraints/AssertFalseValidator.java b/user/src/com/google/gwt/validation/client/constraints/AssertFalseValidator.java
new file mode 100644
index 0000000..ee44197
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AssertFalseValidator.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.AssertFalse;
+
+/**
+ * {@link AssertFalse} constraint validator implementation.
+ */
+public class AssertFalseValidator implements
+ ConstraintValidator<AssertFalse, Boolean> {
+
+ public void initialize(AssertFalse constraintAnnotation) {
+ }
+
+ public boolean isValid(Boolean value, ConstraintValidatorContext context) {
+ return value == null || !value.booleanValue();
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/AssertTrueValidator.java b/user/src/com/google/gwt/validation/client/constraints/AssertTrueValidator.java
new file mode 100644
index 0000000..dfd5827
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/AssertTrueValidator.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.AssertTrue;
+
+/**
+ * {@link AssertTrue} constraint validator implementation.
+ */
+public class AssertTrueValidator implements
+ ConstraintValidator<AssertTrue, Boolean> {
+
+ public void initialize(AssertTrue constraintAnnotation) {
+ }
+
+ public boolean isValid(Boolean value, ConstraintValidatorContext context) {
+ return value == null || value.booleanValue();
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForNumber.java b/user/src/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForNumber.java
new file mode 100644
index 0000000..cda7812
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForNumber.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.DecimalMax} constraint validator
+ * implementation for a {@link Number}.
+ */
+public class DecimalMaxValidatorForNumber extends
+ AbstractDecimalMaxValidator<Number> {
+ @Override
+ public boolean isValid(Number value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ if (value instanceof BigDecimal) {
+ return isValid((BigDecimal) value);
+ }
+ if (value instanceof BigInteger) {
+ return isValid(new BigDecimal((BigInteger) value));
+ }
+ return isValid(BigDecimal.valueOf(value.doubleValue()));
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForString.java b/user/src/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForString.java
new file mode 100644
index 0000000..bf1a8a5
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForString.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.DecimalMax} constraint validator
+ * implementation for a {@link String}.
+ */
+public class DecimalMaxValidatorForString extends
+ AbstractDecimalMaxValidator<String> {
+
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ BigDecimal bigValue;
+ try {
+ bigValue = new BigDecimal(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ return isValid(bigValue);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/DecimalMinValidatorForNumber.java b/user/src/com/google/gwt/validation/client/constraints/DecimalMinValidatorForNumber.java
new file mode 100644
index 0000000..10a9e76
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/DecimalMinValidatorForNumber.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.DecimalMin} constraint validator
+ * implementation for a {@link Number}.
+ */
+public class DecimalMinValidatorForNumber extends
+ AbstractDecimalMinValidator<Number> {
+ @Override
+ public boolean isValid(Number value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ } else if (value instanceof BigDecimal) {
+ BigDecimal bigValue = (BigDecimal) value;
+ return isValid(bigValue);
+ } else if (value instanceof BigInteger) {
+ return isValid(new BigDecimal((BigInteger) value));
+ } else {
+ return isValid(BigDecimal.valueOf(value.doubleValue()));
+ }
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/DecimalMinValidatorForString.java b/user/src/com/google/gwt/validation/client/constraints/DecimalMinValidatorForString.java
new file mode 100644
index 0000000..3b69235
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/DecimalMinValidatorForString.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.DecimalMax} constraint validator
+ * implementation for a {@link String}.
+ */
+public class DecimalMinValidatorForString extends
+ AbstractDecimalMinValidator<String> {
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ BigDecimal bigValue;
+ try {
+ bigValue = new BigDecimal(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ return isValid(bigValue);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/DigitsValidatorForNumber.java b/user/src/com/google/gwt/validation/client/constraints/DigitsValidatorForNumber.java
new file mode 100644
index 0000000..8d83d4b
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/DigitsValidatorForNumber.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Digits} constraint validator
+ * implementation for a {@link Number}.
+ */
+public class DigitsValidatorForNumber extends AbstractDigitsValidator<Number> {
+ @Override
+ public boolean isValid(Number value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ } else if (value instanceof BigDecimal) {
+ BigDecimal bigValue = (BigDecimal) value;
+ return isValid(bigValue);
+ } else if (value instanceof BigInteger) {
+ return isValid(new BigDecimal((BigInteger) value));
+ } else {
+ return isValid(BigDecimal.valueOf(value.doubleValue()));
+ }
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/DigitsValidatorForString.java b/user/src/com/google/gwt/validation/client/constraints/DigitsValidatorForString.java
new file mode 100644
index 0000000..3d89f74
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/DigitsValidatorForString.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Digits} constraint validator
+ * implementation for a {@link String}.
+ */
+public class DigitsValidatorForString extends AbstractDigitsValidator<String> {
+
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ BigDecimal bigValue;
+ try {
+ bigValue = new BigDecimal(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ return isValid(bigValue);
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/FutureValidatorForDate.java b/user/src/com/google/gwt/validation/client/constraints/FutureValidatorForDate.java
new file mode 100644
index 0000000..f007213
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/FutureValidatorForDate.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Future;
+
+/**
+ * {@link Future} constraint validator implementation for a
+ * {@link java.util.Date}.
+ */
+public class FutureValidatorForDate implements
+ ConstraintValidator<Future, Date> {
+
+ public void initialize(Future constraintAnnotation) {
+ }
+
+ public boolean isValid(Date value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return value.after(new Date());
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/MaxValidatorForNumber.java b/user/src/com/google/gwt/validation/client/constraints/MaxValidatorForNumber.java
new file mode 100644
index 0000000..e5fcbb9
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/MaxValidatorForNumber.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Max} constraint validator implementation
+ * for a {@link Number}.
+ */
+public class MaxValidatorForNumber extends AbstractMaxValidator<Number> {
+
+ @Override
+ public boolean isValid(Number value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isValid(value);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/MaxValidatorForString.java b/user/src/com/google/gwt/validation/client/constraints/MaxValidatorForString.java
new file mode 100644
index 0000000..5c068c2
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/MaxValidatorForString.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Max} constraint validator implementation
+ * for a {@link String}.
+ */
+public class MaxValidatorForString extends AbstractMaxValidator<String> {
+
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ BigDecimal bigValue;
+ try {
+ bigValue = new BigDecimal(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ return isValid(bigValue);
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/MinValidatorForNumber.java b/user/src/com/google/gwt/validation/client/constraints/MinValidatorForNumber.java
new file mode 100644
index 0000000..c16969d
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/MinValidatorForNumber.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Min} constraint validator implementation
+ * for a {@link Number}.
+ */
+public class MinValidatorForNumber extends AbstractMinValidator<Number> {
+ @Override
+ public boolean isValid(Number value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isValid(value);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/MinValidatorForString.java b/user/src/com/google/gwt/validation/client/constraints/MinValidatorForString.java
new file mode 100644
index 0000000..669b696
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/MinValidatorForString.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Min} constraint validator implementation
+ * for a {@link String}.
+ */
+public class MinValidatorForString extends AbstractMinValidator<String> {
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ BigDecimal bigValue;
+ try {
+ bigValue = new BigDecimal(value); // TODO(nchalko) deal with i18n
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ return isValid(bigValue);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/NotNullValidator.java b/user/src/com/google/gwt/validation/client/constraints/NotNullValidator.java
new file mode 100644
index 0000000..95aec12
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/NotNullValidator.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.NotNull;
+
+/**
+ * {@link NotNull} constraint validator implementation.
+ */
+public class NotNullValidator implements ConstraintValidator<NotNull, Object> {
+
+ public void initialize(NotNull constraintAnnotation) {
+ }
+
+ public boolean isValid(Object value, ConstraintValidatorContext context) {
+ return value != null;
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/NullValidator.java b/user/src/com/google/gwt/validation/client/constraints/NullValidator.java
new file mode 100644
index 0000000..ed46cd6
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/NullValidator.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Null;
+
+/**
+ * {@link Null} constraint validator implementation.
+ */
+public class NullValidator implements ConstraintValidator<Null, Object> {
+
+ public void initialize(Null constraintAnnotation) {
+ }
+
+ public boolean isValid(Object value, ConstraintValidatorContext context) {
+ return value == null;
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/PastValidatorForDate.java b/user/src/com/google/gwt/validation/client/constraints/PastValidatorForDate.java
new file mode 100644
index 0000000..b34c307
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/PastValidatorForDate.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Past;
+
+/**
+ * {@link Past} constraint validator implementation for a {@link java.util.Date}
+ */
+public class PastValidatorForDate implements ConstraintValidator<Past, Date> {
+
+ public void initialize(Past constraintAnnotation) {
+ }
+
+ public boolean isValid(Date value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return value.before(new Date());
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/PatternValidator.java b/user/src/com/google/gwt/validation/client/constraints/PatternValidator.java
new file mode 100644
index 0000000..59ec77a
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/PatternValidator.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import com.google.gwt.regexp.shared.RegExp;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Pattern.Flag;
+
+/**
+ * {@link Pattern} constraint validator implementation.
+ * <p>
+ * Note this implementation uses {@link RegExp} which differs from
+ * {@link java.util.regex.Pattern}.
+ */
+public class PatternValidator implements ConstraintValidator<Pattern, String> {
+ private RegExp pattern;
+
+ public void initialize(Pattern annotation) {
+ Pattern.Flag flags[] = annotation.flags();
+ String flagString = "";
+ for (Pattern.Flag flag : flags) {
+ flagString += toString(flag);
+ }
+ pattern = RegExp.compile(annotation.regexp(), flagString);
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ return value == null || pattern.exec(value) != null;
+ }
+
+ private String toString(Flag flag) {
+ String value;
+ switch (flag) {
+ case CASE_INSENSITIVE:
+ case UNICODE_CASE:
+ value = "i";
+ break;
+ case MULTILINE:
+ value = "m";
+ break;
+ default:
+ throw new IllegalArgumentException(flag
+ + " is not a suppoted gwt Pattern (RegExp) flag");
+ }
+ return value;
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfBoolean.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfBoolean.java
new file mode 100644
index 0000000..40f8d01
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfBoolean.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link boolean}s.
+ */
+public class SizeValidatorForArrayOfBoolean extends
+ AbstractSizeValidator<boolean[]> {
+
+ @Override
+ public boolean isValid(boolean[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfByte.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfByte.java
new file mode 100644
index 0000000..03ee623
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfByte.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link byte}s.
+ */
+public class SizeValidatorForArrayOfByte extends AbstractSizeValidator<byte[]> {
+
+ @Override
+ public boolean isValid(byte[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfChar.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfChar.java
new file mode 100644
index 0000000..9ccb329
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfChar.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link char}s.
+ */
+public class SizeValidatorForArrayOfChar extends AbstractSizeValidator<char[]> {
+
+ @Override
+ public boolean isValid(char[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfDouble.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfDouble.java
new file mode 100644
index 0000000..881cf28
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfDouble.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link double}s.
+ */
+public class SizeValidatorForArrayOfDouble extends
+ AbstractSizeValidator<double[]> {
+
+ @Override
+ public boolean isValid(double[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfFloat.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfFloat.java
new file mode 100644
index 0000000..fe5fdf8
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfFloat.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link float}s.
+ */
+public class SizeValidatorForArrayOfFloat extends
+ AbstractSizeValidator<float[]> {
+
+ @Override
+ public boolean isValid(float[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfInt.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfInt.java
new file mode 100644
index 0000000..b3377b2
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfInt.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link int}s.
+ */
+public class SizeValidatorForArrayOfInt extends AbstractSizeValidator<int[]> {
+
+ @Override
+ public boolean isValid(int[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfLong.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfLong.java
new file mode 100644
index 0000000..8a9f253
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfLong.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link long}s.
+ */
+public class SizeValidatorForArrayOfLong extends AbstractSizeValidator<long[]> {
+
+ @Override
+ public boolean isValid(long[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfObject.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfObject.java
new file mode 100644
index 0000000..07cead2
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfObject.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link Object}s.
+ */
+public class SizeValidatorForArrayOfObject extends
+ AbstractSizeValidator<Object[]> {
+
+ @Override
+ public boolean isValid(Object[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfShort.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfShort.java
new file mode 100644
index 0000000..83237f5
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfShort.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a array of {@link short}s.
+ */
+public class SizeValidatorForArrayOfShort extends
+ AbstractSizeValidator<short[]> {
+
+ @Override
+ public boolean isValid(short[] value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length);
+ }
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForCollection.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForCollection.java
new file mode 100644
index 0000000..a55ae96
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForCollection.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Collection;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a {@link Collection}.
+ */
+public class SizeValidatorForCollection extends
+ AbstractSizeValidator<Collection<?>> {
+
+ @Override
+ public boolean isValid(Collection<?> value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.size());
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForMap.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForMap.java
new file mode 100644
index 0000000..01d548c
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForMap.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Map;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a {@link Map}.
+ */
+public class SizeValidatorForMap extends AbstractSizeValidator<Map<?, ?>> {
+
+ @Override
+ public boolean isValid(Map<?, ?> value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.size());
+ }
+
+}
diff --git a/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForString.java b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForString.java
new file mode 100644
index 0000000..30eb208
--- /dev/null
+++ b/user/src/com/google/gwt/validation/client/constraints/SizeValidatorForString.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * {@link javax.validation.constraints.Size} constraint validator implementation
+ * for a {@link String}.
+ */
+public class SizeValidatorForString extends AbstractSizeValidator<String> {
+
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ return isLengthValid(value.length());
+ }
+}
diff --git a/user/src/javax/validation/Validation.gwt.xml b/user/src/javax/validation/Validation.gwt.xml
index c232374..9eec257 100644
--- a/user/src/javax/validation/Validation.gwt.xml
+++ b/user/src/javax/validation/Validation.gwt.xml
@@ -17,5 +17,8 @@
-->
<!-- Includes the javax.validation classes from the source jar -->
<module>
- <source path=""/>
+ <source path="">
+ <exclude name="super/"/>
+ </source>
+ <super-source path="super"/>
</module>
\ No newline at end of file
diff --git a/user/src/javax/validation/super/javax/validation/constraints/Pattern.java b/user/src/javax/validation/super/javax/validation/constraints/Pattern.java
new file mode 100644
index 0000000..017edfe
--- /dev/null
+++ b/user/src/javax/validation/super/javax/validation/constraints/Pattern.java
@@ -0,0 +1,159 @@
+// $Id: Pattern.java 17620 2009-10-04 19:19:28Z hardy.ferentschik $
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, Red Hat, Inc. and/or
+ * its affiliates, and individual contributors by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * 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.
+ */
+// Modified by Google.
+package javax.validation.constraints;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+/**
+ * The annotated String must match the following regular expression. The regular
+ * expression follows the Java regular expression conventions see
+ * {@link java.util.regex.Pattern}.
+ *
+ * <p>
+ * Accepts String. <code>null</code> elements are considered valid.
+ *
+ * <p>
+ * GWT Modification: Reference to java.util.regex.Pattern are inlined
+ *
+ * @author Emmanuel Bernard
+ */
+@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
+@Retention(RUNTIME)
+@Documented
+@Constraint(validatedBy = {})
+public @interface Pattern {
+ /**
+ * @return The regular expression to match.
+ */
+ String regexp();
+
+ /**
+ * @return Array of <code>Flag</code>s considered when resolving the regular
+ * expression.
+ */
+ Flag[] flags() default {};
+
+ /**
+ * @return The error message template.
+ */
+ String message() default "{javax.validation.constraints.Pattern.message}";
+
+ /**
+ * @return The groups the constraint belongs to.
+ */
+ Class<?>[] groups() default {};
+
+ /**
+ * @return The payload associated to the constraint
+ */
+ Class<? extends Payload>[] payload() default {};
+
+ /**
+ * Possible Regexp flags
+ */
+ public static enum Flag {
+
+ /**
+ * Enables Unix lines mode
+ *
+ * @see java.util.regex.Pattern#UNIX_LINES
+ */
+ UNIX_LINES(1),
+
+ /**
+ * Enables case-insensitive matching
+ *
+ * @see java.util.regex.Pattern#CASE_INSENSITIVE
+ */
+ CASE_INSENSITIVE(2),
+
+ /**
+ * Permits whitespace and comments in pattern
+ *
+ * @see java.util.regex.Pattern#COMMENTS
+ */
+ COMMENTS(4),
+
+ /**
+ * Enables multiline mode
+ *
+ * @see java.util.regex.Pattern#MULTILINE
+ */
+ MULTILINE(8),
+
+ /**
+ * Enables dotall mode
+ *
+ * @see java.util.regex.Pattern#DOTALL
+ */
+ DOTALL(32),
+
+ /**
+ * Enables Unicode-aware case folding
+ *
+ * @see java.util.regex.Pattern#UNICODE_CASE
+ */
+ UNICODE_CASE(64),
+
+ /**
+ * Enables canonical equivalence
+ *
+ * @see java.util.regex.Pattern#CANON_EQ
+ */
+ CANON_EQ(128);
+
+ // JDK flag value
+ private final int value;
+
+ private Flag(int value) {
+ this.value = value;
+ }
+
+ /**
+ * @return flag value as defined in {@link java.util.regex.Pattern}
+ */
+ public int getValue() {
+ return value;
+ }
+ }
+
+ /**
+ * Defines several <code>@Pattern</code> annotations on the same element
+ *
+ * @see Pattern
+ *
+ * @author Emmanuel Bernard
+ */
+ @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
+ @Retention(RUNTIME)
+ @Documented
+ @interface List {
+ Pattern[] value();
+ }
+}
diff --git a/user/test/com/google/gwt/validation/ValidationSuite.java b/user/test/com/google/gwt/validation/ValidationGwtSuite.java
similarity index 96%
rename from user/test/com/google/gwt/validation/ValidationSuite.java
rename to user/test/com/google/gwt/validation/ValidationGwtSuite.java
index d706472..d366007 100644
--- a/user/test/com/google/gwt/validation/ValidationSuite.java
+++ b/user/test/com/google/gwt/validation/ValidationGwtSuite.java
@@ -23,7 +23,7 @@
/**
* All validation tests.
*/
-public class ValidationSuite {
+public class ValidationGwtSuite {
public static Test suite() {
GWTTestSuite suite = new GWTTestSuite(
diff --git a/user/test/com/google/gwt/validation/client/constraints/AssertFalseValidatorTest.java b/user/test/com/google/gwt/validation/client/constraints/AssertFalseValidatorTest.java
new file mode 100644
index 0000000..771247a
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/AssertFalseValidatorTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.AssertFalse;
+
+/**
+ * Tests for {@link AssertFalseValidator}.
+ */
+public class AssertFalseValidatorTest extends
+ ConstraintValidatorTestCase<AssertFalse, Boolean> {
+
+ @SuppressWarnings("unused")
+ @AssertFalse
+ private Boolean defaultField;
+
+ protected AssertFalseValidator createValidator() {
+ return new AssertFalseValidator();
+ }
+
+ public void testIsValid_false() {
+ Boolean value = Boolean.FALSE;
+ boolean expected = true;
+ assertConstraintValidator(value, expected);
+ }
+
+ public void testIsValid_true() {
+ assertConstraintValidator(Boolean.TRUE, false);
+ }
+
+ @Override
+ protected Class<AssertFalse> getAnnotationClass() {
+ return AssertFalse.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/AssertTrueValidatorTest.java b/user/test/com/google/gwt/validation/client/constraints/AssertTrueValidatorTest.java
new file mode 100644
index 0000000..5ff0379
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/AssertTrueValidatorTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.AssertTrue;
+
+/**
+ * Tests for {@link AssertFalseValidator}.
+ */
+public class AssertTrueValidatorTest extends
+ ConstraintValidatorTestCase<AssertTrue, Boolean> {
+
+ @SuppressWarnings("unused")
+ @AssertTrue
+ private Boolean defaultField;
+
+ @Override
+ protected AssertTrueValidator createValidator() {
+ return new AssertTrueValidator();
+ }
+
+ public void testIsValid_false() {
+ assertConstraintValidator(Boolean.FALSE, false);
+ }
+
+ public void testIsValid_true() {
+ assertConstraintValidator(Boolean.TRUE, true);
+ }
+
+ @Override
+ protected Class<AssertTrue> getAnnotationClass() {
+ return AssertTrue.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/ConstraintValidatorTestCase.java b/user/test/com/google/gwt/validation/client/constraints/ConstraintValidatorTestCase.java
new file mode 100644
index 0000000..d267949
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/ConstraintValidatorTestCase.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * TestCase for {@link javax.validation.ConstraintValidator}s.
+ * <p>
+ * Subclasses must :
+ * <ul>
+ * <li>implement {@link #getAnnotationClass()}</li>
+ * <li>implement {@link #createValidator()}.</li>
+ * <li>define a field called <code>defaultField</code> and annotate it with the
+ * constraint Annotation under test</li>
+ * </ul>
+ *
+ * <p>
+ * If additional instances of the annotation need to be tested you can get there
+ * value with {@link #getAnnotation(Class, Class, String)}
+ *
+ * @param <A> The constraint Annotation of the ConstraintValidator under test
+ * @param <T> The bean type of the ConstraintValidator under test
+ */
+public abstract class ConstraintValidatorTestCase<A extends Annotation, T>
+ extends TestCase {
+
+ public final static String DEFAULT_ANNOTATED_FIELD_NAME = "defaultField";
+
+ // Validators are reusable but not thread safe
+ protected final ConstraintValidator<A, T> validator = createValidator();
+
+ // private ConstraintValidatorContext context;
+
+ public ConstraintValidatorTestCase() {
+ super();
+ }
+
+ /**
+ * All constraints except {@link NotNull} should return true for a null value.
+ */
+ public final void testIsValid_null() {
+ ConstraintValidatorTestCase.assertConstraintValidator(validator,
+ getDefaultAnnotation(), null, null, isNullValid());
+ }
+
+ /**
+ * Override this if a null value should not be valid. This is called by
+ * {@link #testIsValid_null()}
+ */
+ protected boolean isNullValid() {
+ return true;
+ }
+
+ /**
+ * Get the annotation of type {@link #getAnnotationClass()} on the field named
+ * <code>defaultField</code>.
+ */
+ protected final A getDefaultAnnotation() {
+ return getAnnotation(getAnnotationClass(), this.getClass(),
+ DEFAULT_ANNOTATED_FIELD_NAME);
+ }
+
+ protected abstract Class<A> getAnnotationClass();
+
+ protected A getAnnotation(Class<A> annotationClass, Class<?> objectClass,
+ String fieldName) {
+
+ for (Field field : objectClass.getDeclaredFields()) {
+ if (field.getName().equals(fieldName)) {
+ A annotation = field.getAnnotation(annotationClass);
+ if (annotation == null) {
+ throw new IllegalArgumentException(objectClass + "." + fieldName
+ + " is not annotated with " + annotationClass);
+ }
+ return annotation;
+ }
+ }
+ throw new IllegalArgumentException(objectClass
+ + " does not have a field called " + fieldName);
+ }
+
+ protected abstract ConstraintValidator<A, T> createValidator();
+
+ /**
+ * Assert result of validating <code>value</code> with <code>validator</code>
+ * initialized with the annotation of the <code>defaultField</code>.
+ *
+ * @param value the Value to validate
+ * @param expected the expected result of a calling <code>isValid</code>
+ */
+ protected void assertConstraintValidator(T value, boolean expected) {
+ assertConstraintValidator(validator, getDefaultAnnotation(), null, value,
+ expected);
+ }
+
+ /**
+ * Asserts the validity of a value using the given validator, annotation, and
+ * context.
+ *
+ * @param <T> object type
+ * @param <A> the constraint annotation type
+ * @param validator the {@link ConstraintValidator} to test
+ * @param annotation the constraint annotation to initialize the validator.
+ * @param context The context for the validator
+ * @param value the value to validate.
+ * @param expected the expected result
+ */
+ public static <T, A extends Annotation> void assertConstraintValidator(
+ ConstraintValidator<A, T> validator, A annotation,
+ ConstraintValidatorContext context, T value, boolean expected) {
+ validator.initialize(annotation);
+ String message = validator.getClass().getName() + "(" + annotation
+ + ").isValid(" + value + ", " + context + ")";
+ assertEquals(message, expected, validator.isValid(value, context));
+ }
+
+}
diff --git a/user/test/com/google/gwt/validation/ValidationSuite.java b/user/test/com/google/gwt/validation/client/constraints/ConstraintsGwtSuite.java
similarity index 75%
copy from user/test/com/google/gwt/validation/ValidationSuite.java
copy to user/test/com/google/gwt/validation/client/constraints/ConstraintsGwtSuite.java
index d706472..45ca523 100644
--- a/user/test/com/google/gwt/validation/ValidationSuite.java
+++ b/user/test/com/google/gwt/validation/client/constraints/ConstraintsGwtSuite.java
@@ -13,22 +13,20 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.validation;
+package com.google.gwt.validation.client.constraints;
import com.google.gwt.junit.tools.GWTTestSuite;
-import com.google.gwt.validation.client.SimpleSampleTest;
import junit.framework.Test;
/**
- * All validation tests.
+ * All Constraints tests that GWTTestCase.
*/
-public class ValidationSuite {
-
+public class ConstraintsGwtSuite {
public static Test suite() {
GWTTestSuite suite = new GWTTestSuite(
- "Test suite for all validation code.");
- suite.addTestSuite(SimpleSampleTest.class);
+ "Validation Constraint tests that require GWT");
+ suite.addTestSuite(GwtCompileTest.class);
return suite;
}
diff --git a/user/test/com/google/gwt/validation/client/constraints/ConstraintsJreSuite.java b/user/test/com/google/gwt/validation/client/constraints/ConstraintsJreSuite.java
new file mode 100644
index 0000000..98f1a38
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/ConstraintsJreSuite.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * All Constraints tests that don't need GWTTestCase.
+ */
+public class ConstraintsJreSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Validation Constraint tests that require the JRE");
+ suite.addTestSuite(AssertFalseValidatorTest.class);
+ suite.addTestSuite(AssertTrueValidatorTest.class);
+ suite.addTestSuite(DecimalMaxValidatorForNumberTest.class);
+ suite.addTestSuite(DecimalMaxValidatorForStringTest.class);
+ suite.addTestSuite(DecimalMinValidatorForNumberTest.class);
+ suite.addTestSuite(DecimalMinValidatorForStringTest.class);
+ suite.addTestSuite(DigitsValidatorForNumberTest.class);
+ suite.addTestSuite(DigitsValidatorForStringTest.class);
+ suite.addTestSuite(FutureValidatorForDateTest.class);
+ suite.addTestSuite(MaxValidatorForNumberTest.class);
+ suite.addTestSuite(MaxValidatorForStringTest.class);
+ suite.addTestSuite(MinValidatorForNumberTest.class);
+ suite.addTestSuite(MinValidatorForStringTest.class);
+ suite.addTestSuite(NotNullValidatorTest.class);
+ suite.addTestSuite(NullValidatorTest.class);
+ suite.addTestSuite(PastValidatorForDateTest.class);
+ suite.addTestSuite(PatternValidatorTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfBooleanTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfByteTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfCharTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfDoubleTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfFloatTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfIntTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfLongTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfObjectTest.class);
+ suite.addTestSuite(SizeValidatorForArrayOfShortTest.class);
+ suite.addTestSuite(SizeValidatorForCollectionTest.class);
+ suite.addTestSuite(SizeValidatorForMapTest.class);
+ suite.addTestSuite(SizeValidatorForCollectionTest.class);
+ suite.addTestSuite(SizeValidatorForMapTest.class);
+ suite.addTestSuite(SizeValidatorForStringTest.class);
+ return suite;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForNumberTest.java b/user/test/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForNumberTest.java
new file mode 100644
index 0000000..45edfbf
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForNumberTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.DecimalMax;
+
+/**
+ * Tests for {@link DecimalMaxValidatorForNumber}
+ */
+public class DecimalMaxValidatorForNumberTest extends
+ ConstraintValidatorTestCase<DecimalMax, Number> {
+ private static Double BELOW = Double.valueOf(922392239223.08);
+ private static Double SAME = Double.valueOf(922392239223.09);
+ private static Double ABOVE = Double.valueOf(922392239223.10);
+
+ @SuppressWarnings("unused")
+ @DecimalMax("922392239223.09")
+ private double defaultField;
+
+ protected DecimalMaxValidatorForNumber createValidator() {
+ return new DecimalMaxValidatorForNumber();
+ }
+
+ public void testIsValid_below() {
+ assertConstraintValidator(BELOW, true);
+ }
+
+ public void testIsValid_same() {
+ assertConstraintValidator(SAME, true);
+ }
+
+ public void testIsValid_above() {
+ assertConstraintValidator(ABOVE, false);
+ }
+
+ @Override
+ protected Class<DecimalMax> getAnnotationClass() {
+ return DecimalMax.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForStringTest.java b/user/test/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForStringTest.java
new file mode 100644
index 0000000..85a8151
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/DecimalMaxValidatorForStringTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.DecimalMax;
+
+/**
+ * Tests for {@link DecimalMaxValidatorForString}
+ */
+public class DecimalMaxValidatorForStringTest extends
+ ConstraintValidatorTestCase<DecimalMax, String> {
+ private static String BELOW = "922392239223.08";
+ private static String SAME = "922392239223.09";
+ private static String ABOVE = "922392239223.10";
+
+ @SuppressWarnings("unused")
+ @DecimalMax("922392239223.09")
+ private String defaultField;
+
+ protected DecimalMaxValidatorForString createValidator() {
+ return new DecimalMaxValidatorForString();
+ }
+
+ public void testIsValid_below() {
+ assertConstraintValidator(BELOW, true);
+ }
+
+ public void testIsValid_same() {
+ assertConstraintValidator(SAME, true);
+ }
+
+ public void testIsValid_above() {
+ assertConstraintValidator(ABOVE, false);
+ }
+
+ public void testIsValid_invalid() {
+ assertConstraintValidator("invalid", false);
+ }
+
+ @Override
+ protected Class<DecimalMax> getAnnotationClass() {
+ return DecimalMax.class;
+ }
+
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/DecimalMinValidatorForNumberTest.java b/user/test/com/google/gwt/validation/client/constraints/DecimalMinValidatorForNumberTest.java
new file mode 100644
index 0000000..03ed79c
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/DecimalMinValidatorForNumberTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.DecimalMin;
+
+/**
+ * Tests for {@link DecimalMinValidatorForNumber}
+ */
+public class DecimalMinValidatorForNumberTest extends
+ ConstraintValidatorTestCase<DecimalMin, Number> {
+ private static Double BELOW = Double.valueOf(922392239223.08);
+ private static Double ABOVE = Double.valueOf(922392239223.10);
+
+ @SuppressWarnings("unused")
+ @DecimalMin("922392239223.09")
+ private double defaultField;
+
+ protected DecimalMinValidatorForNumber createValidator() {
+ return new DecimalMinValidatorForNumber();
+ }
+
+ public void testIsValid_below() {
+ assertConstraintValidator(BELOW, false);
+ }
+
+ // Because of rounding error we can't actually test for the exact vale
+
+ public void testIsValid_above() {
+ assertConstraintValidator(ABOVE, true);
+ }
+
+ @Override
+ protected Class<DecimalMin> getAnnotationClass() {
+ return DecimalMin.class;
+ }
+
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/DecimalMinValidatorForStringTest.java b/user/test/com/google/gwt/validation/client/constraints/DecimalMinValidatorForStringTest.java
new file mode 100644
index 0000000..089c5f0
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/DecimalMinValidatorForStringTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.DecimalMin;
+
+/**
+ * Tests for {@link DecimalMinValidatorForString}
+ */
+public class DecimalMinValidatorForStringTest extends
+ ConstraintValidatorTestCase<DecimalMin, String> {
+ private static String BELOW = "922392239223.08";
+ private static String SAME = "922392239223.09";
+ private static String ABOVE = "922392239223.10";
+
+ @SuppressWarnings("unused")
+ @DecimalMin("922392239223.09")
+ private double defaultField;
+
+ protected DecimalMinValidatorForString createValidator() {
+ return new DecimalMinValidatorForString();
+ }
+
+ public void testIsValid_below() {
+ assertConstraintValidator(BELOW, false);
+ }
+
+ public void testIsValid_same() {
+ assertConstraintValidator(SAME, true);
+ }
+
+ public void testIsValid_above() {
+ assertConstraintValidator(ABOVE, true);
+ }
+
+ public void testIsValid_invalid() {
+ assertConstraintValidator("invalid", false);
+ }
+
+ @Override
+ protected Class<DecimalMin> getAnnotationClass() {
+ return DecimalMin.class;
+ }
+
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/DigitsValidatorForNumberTest.java b/user/test/com/google/gwt/validation/client/constraints/DigitsValidatorForNumberTest.java
new file mode 100644
index 0000000..9c0cdbb
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/DigitsValidatorForNumberTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.math.BigDecimal;
+
+import javax.validation.constraints.Digits;
+
+/**
+ * Tests for {@link DigitsValidatorForNumber}
+ */
+public class DigitsValidatorForNumberTest extends
+ ConstraintValidatorTestCase<Digits, Number> {
+
+ private static BigDecimal GOOD = new BigDecimal("1234.12");
+ private static BigDecimal INT_TO_BIG = new BigDecimal("12345.12");
+ private static BigDecimal INT_SMALL = new BigDecimal("123.12");
+ private static BigDecimal DECIMAL_TO_BIG = new BigDecimal("1234.123");
+ private static BigDecimal DECIMAL_SMALL = new BigDecimal("1234.1");
+
+ @SuppressWarnings("unused")
+ @Digits(integer = 4, fraction = 2)
+ private double defaultField;
+
+ protected DigitsValidatorForNumber createValidator() {
+ return new DigitsValidatorForNumber();
+ }
+
+ public void testIsValid_decimalToBig() {
+ assertConstraintValidator(DECIMAL_SMALL, true);
+ }
+
+ public void testIsValid_decimalToSmall() {
+ assertConstraintValidator(DECIMAL_TO_BIG, false);
+ }
+
+ public void testIsValid_good() {
+ assertConstraintValidator(GOOD, true);
+ }
+
+ public void testIsValid_intToBig() {
+ assertConstraintValidator(INT_TO_BIG, false);
+ }
+
+ public void testIsValid_intToSmall() {
+ assertConstraintValidator(INT_SMALL, true);
+ }
+
+ @Override
+ protected Class<Digits> getAnnotationClass() {
+ return Digits.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/DigitsValidatorForStringTest.java b/user/test/com/google/gwt/validation/client/constraints/DigitsValidatorForStringTest.java
new file mode 100644
index 0000000..e3d30fc
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/DigitsValidatorForStringTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.Digits;
+
+/**
+ * Tests for {@link DigitsValidatorForString}
+ */
+public class DigitsValidatorForStringTest extends
+ ConstraintValidatorTestCase<Digits, String> {
+
+ private static String GOOD = "1234.12";
+ private static String INT_TO_BIG = "12345.12";
+ private static String INT_SMALL = "123.12";
+ private static String DECIMAL_TO_BIG = "1234.123";
+ private static String DECIMAL_SMALL = "1234.1";
+
+ @SuppressWarnings("unused")
+ @Digits(integer = 4, fraction = 2)
+ private double defaultField;
+
+ protected DigitsValidatorForString createValidator() {
+ return new DigitsValidatorForString();
+ }
+
+ public void testIsValid_decimalToBig() {
+ assertConstraintValidator(DECIMAL_SMALL, true);
+ }
+
+ public void testIsValid_decimalToSmall() {
+ assertConstraintValidator(DECIMAL_TO_BIG, false);
+ }
+
+ public void testIsValid_good() {
+ assertConstraintValidator(GOOD, true);
+ }
+
+ public void testIsValid_intToBig() {
+ assertConstraintValidator(INT_TO_BIG, false);
+ }
+
+ public void testIsValid_intToSmall() {
+ assertConstraintValidator(INT_SMALL, true);
+ }
+
+ public void testIsValid_invalid() {
+ assertConstraintValidator("invalid", false);
+ }
+
+ @Override
+ protected Class<Digits> getAnnotationClass() {
+ return Digits.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/FutureValidatorForDateTest.java b/user/test/com/google/gwt/validation/client/constraints/FutureValidatorForDateTest.java
new file mode 100644
index 0000000..4ed5ebd
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/FutureValidatorForDateTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Future;
+
+/**
+ * Tests for {@link FutureValidatorForDate}
+ */
+public class FutureValidatorForDateTest extends
+ ConstraintValidatorTestCase<Future, Date> {
+
+
+ @SuppressWarnings("unused")
+ @Future
+ private Date defaultField;
+
+ protected FutureValidatorForDate createValidator() {
+ return new FutureValidatorForDate();
+ }
+
+ public void testAssertIsValid_nowMinus1000() {
+ assertConstraintValidator(new Date(new Date().getTime() - 1000), false);
+ }
+
+ public void testAssertIsValid_nowPlus1000() {
+ assertConstraintValidator(new Date(new Date().getTime() + 1000), true);
+ }
+
+ @Override
+ protected Class<Future> getAnnotationClass() {
+ return Future.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/GwtCompileTest.java b/user/test/com/google/gwt/validation/client/constraints/GwtCompileTest.java
new file mode 100644
index 0000000..0443a79
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/GwtCompileTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A GWT test to force the compilation of all default standard
+ * {@link javax.validation.ConstraintValidator}s.
+ */
+public class GwtCompileTest extends GWTTestCase {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.validation.Validation";
+ }
+
+ public void testDefaultConstraints() {
+ List<Class<?>> temp = new ArrayList<Class<?>>();
+ temp.add(AssertFalseValidator.class);
+ temp.add(AssertTrueValidator.class);
+ temp.add(DecimalMaxValidatorForNumber.class);
+ temp.add(DecimalMaxValidatorForString.class);
+ temp.add(DecimalMinValidatorForNumber.class);
+ temp.add(DecimalMinValidatorForString.class);
+ temp.add(DigitsValidatorForNumber.class);
+ temp.add(DigitsValidatorForString.class);
+ // FutureValidatorForCalendar GWT does not support java.util.Calendar
+ temp.add(FutureValidatorForDate.class);
+ temp.add(MaxValidatorForNumber.class);
+ temp.add(MaxValidatorForString.class);
+ temp.add(MinValidatorForNumber.class);
+ temp.add(MinValidatorForString.class);
+ temp.add(NotNullValidator.class);
+ temp.add(NullValidator.class);
+ // PastValidatorForCalendar GWT does not support java.util.Calendar
+ temp.add(PastValidatorForDate.class);
+ temp.add(PatternValidator.class);
+ temp.add(SizeValidatorForArrayOfBoolean.class);
+ temp.add(SizeValidatorForArrayOfByte.class);
+ temp.add(SizeValidatorForArrayOfChar.class);
+ temp.add(SizeValidatorForArrayOfDouble.class);
+ temp.add(SizeValidatorForArrayOfFloat.class);
+ temp.add(SizeValidatorForArrayOfInt.class);
+ temp.add(SizeValidatorForArrayOfLong.class);
+ temp.add(SizeValidatorForArrayOfObject.class);
+ temp.add(SizeValidatorForArrayOfShort.class);
+ temp.add(SizeValidatorForCollection.class);
+ temp.add(SizeValidatorForMap.class);
+ temp.add(SizeValidatorForString.class);
+
+ assertEquals(29, temp.size());
+ }
+
+
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/MaxValidatorForNumberTest.java b/user/test/com/google/gwt/validation/client/constraints/MaxValidatorForNumberTest.java
new file mode 100644
index 0000000..6b177dc
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/MaxValidatorForNumberTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.Max;
+
+/**
+ * Tests for {@link MaxValidatorForNumber}
+ */
+public class MaxValidatorForNumberTest extends
+ ConstraintValidatorTestCase<Max, Number> {
+ private static long SAME = 123456789L;
+ private static long SMALLER = SAME - 1L;
+ private static long BIGGER = SAME + 1L;
+
+ @Max(123456789L)
+ public long defaultField;
+
+ public void testIsValid_same() {
+ assertConstraintValidator(Long.valueOf(SAME), true);
+ }
+
+ public void testIsValid_smaller() {
+ assertConstraintValidator(Long.valueOf(SMALLER), true);
+ }
+
+ public void testIsValid_bigger() {
+ assertConstraintValidator(Long.valueOf(BIGGER), false);
+ }
+
+ public void testIsValid_minValue() {
+ assertConstraintValidator(Long.valueOf(Long.MIN_VALUE), true);
+ }
+
+ public void testIsValid_maxValue() {
+ assertConstraintValidator(Long.valueOf(Long.MAX_VALUE), false);
+ }
+
+ @Override
+ protected MaxValidatorForNumber createValidator() {
+ return new MaxValidatorForNumber();
+ }
+
+ @Override
+ protected Class<Max> getAnnotationClass() {
+ return Max.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/MaxValidatorForStringTest.java b/user/test/com/google/gwt/validation/client/constraints/MaxValidatorForStringTest.java
new file mode 100644
index 0000000..959fe90
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/MaxValidatorForStringTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.Max;
+
+/**
+ * Tests for {@link MinValidatorForString}
+ */
+public class MaxValidatorForStringTest extends
+ ConstraintValidatorTestCase<Max, String> {
+ private static String SAME = "123456789";
+ private static String SMALLER = "123456788";
+ private static String BIGGER = "123456790";
+
+ @Max(123456789)
+ public String defaultField;
+
+ public void testIsValid_same() {
+ assertConstraintValidator(SAME, true);
+ }
+
+ public void testIsValid_smaller() {
+ assertConstraintValidator(SMALLER, true);
+ }
+
+ public void testIsValid_bigger() {
+ assertConstraintValidator(BIGGER, false);
+ }
+
+ public void testIsValid_minValue() {
+ assertConstraintValidator(Long.valueOf(Long.MIN_VALUE).toString(), true);
+ }
+
+ public void testIsValid_maxValue() {
+ assertConstraintValidator(Long.valueOf(Long.MAX_VALUE).toString(), false);
+ }
+
+ public void testIsValid_invalid() {
+ assertConstraintValidator("invalid", false);
+ }
+
+ @Override
+ protected MaxValidatorForString createValidator() {
+ return new MaxValidatorForString();
+ }
+
+ @Override
+ protected Class<Max> getAnnotationClass() {
+ return Max.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/MinValidatorForNumberTest.java b/user/test/com/google/gwt/validation/client/constraints/MinValidatorForNumberTest.java
new file mode 100644
index 0000000..522528e
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/MinValidatorForNumberTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.Min;
+
+/**
+ * Tests for {@link MinValidatorForNumber}
+ */
+public class MinValidatorForNumberTest extends
+ ConstraintValidatorTestCase<Min, Number> {
+ private static long SAME = 123456789L;
+ private static long SMALLER = SAME - 1L;
+ private static long BIGGER = SAME + 1L;
+
+ @Min(123456789L)
+ public long defaultField;
+
+ public void testIsValid_same() {
+ assertConstraintValidator(Long.valueOf(SAME), true);
+ }
+
+ public void testIsValid_smaller() {
+ assertConstraintValidator(Long.valueOf(SMALLER), false);
+ }
+
+ public void testIsValid_bigger() {
+ assertConstraintValidator(Long.valueOf(BIGGER), true);
+ }
+
+ public void testIsValid_minValue() {
+ assertConstraintValidator(Long.valueOf(Long.MIN_VALUE), false);
+ }
+
+ public void testIsValid_maxValue() {
+ assertConstraintValidator(Long.valueOf(Long.MAX_VALUE), true);
+ }
+
+ @Override
+ protected MinValidatorForNumber createValidator() {
+ return new MinValidatorForNumber();
+ }
+
+ @Override
+ protected Class<Min> getAnnotationClass() {
+ return Min.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/MinValidatorForStringTest.java b/user/test/com/google/gwt/validation/client/constraints/MinValidatorForStringTest.java
new file mode 100644
index 0000000..475de21
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/MinValidatorForStringTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.Max;
+
+/**
+ * Tests for {@link MinValidatorForString}
+ */
+public class MinValidatorForStringTest extends
+ ConstraintValidatorTestCase<Max, String> {
+ private static String SAME = "123456789";
+ private static String SMALLER = "123456788";
+ private static String BIGGER = "123456790";
+
+ @Max(123456789)
+ public String defaultField;
+
+ public void testIsValid_same() {
+ assertConstraintValidator(SAME, true);
+ }
+
+ public void testIsValid_smaller() {
+ assertConstraintValidator(SMALLER, true);
+ }
+
+ public void testIsValid_bigger() {
+ assertConstraintValidator(BIGGER, false);
+ }
+
+ public void testIsValid_minValue() {
+ assertConstraintValidator(Long.valueOf(Long.MIN_VALUE).toString(), true);
+ }
+
+ public void testIsValid_maxValue() {
+ assertConstraintValidator(Long.valueOf(Long.MAX_VALUE).toString(), false);
+ }
+
+ public void testIsValid_invalid() {
+ assertConstraintValidator("invalid", false);
+ }
+
+ @Override
+ protected MaxValidatorForString createValidator() {
+ return new MaxValidatorForString();
+ }
+
+ @Override
+ protected Class<Max> getAnnotationClass() {
+ return Max.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/NotNullValidatorTest.java b/user/test/com/google/gwt/validation/client/constraints/NotNullValidatorTest.java
new file mode 100644
index 0000000..c423d17
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/NotNullValidatorTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.NotNull;
+
+/**
+ * Tests for {@link NotNullValidator}
+ */
+public class NotNullValidatorTest extends
+ ConstraintValidatorTestCase<NotNull, Object> {
+
+ @SuppressWarnings("unused")
+ @NotNull
+ private String defaultField;
+
+ public void testIsValid_notNull() {
+ ConstraintValidatorTestCase.assertConstraintValidator(validator,
+ getDefaultAnnotation(), null, new Object(), true);
+ }
+
+ @Override
+ protected boolean isNullValid() {
+ return false;
+ }
+
+ @Override
+ protected Class<NotNull> getAnnotationClass() {
+ return NotNull.class;
+ }
+
+ @Override
+ protected ConstraintValidator<NotNull, Object> createValidator() {
+ return new NotNullValidator();
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/NullValidatorTest.java b/user/test/com/google/gwt/validation/client/constraints/NullValidatorTest.java
new file mode 100644
index 0000000..7197064
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/NullValidatorTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import javax.validation.constraints.Null;
+
+/**
+ * Tests for {@link NullValidator}.
+ */
+public class NullValidatorTest extends
+ ConstraintValidatorTestCase<Null, Object> {
+
+ @SuppressWarnings("unused")
+ @Null
+ private Object defaultField;
+
+ protected NullValidator createValidator() {
+ return new NullValidator();
+ }
+
+ public void testIsValid_notNull() {
+ assertConstraintValidator("this is not null", false);
+ }
+
+ @Override
+ protected Class<Null> getAnnotationClass() {
+ return Null.class;
+ }
+
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/PastValidatorForDateTest.java b/user/test/com/google/gwt/validation/client/constraints/PastValidatorForDateTest.java
new file mode 100644
index 0000000..7223da7
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/PastValidatorForDateTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Past;
+
+/**
+ * Tests for {@link PastValidatorForDate}
+ */
+public class PastValidatorForDateTest extends
+ ConstraintValidatorTestCase<Past, Date> {
+
+
+ @SuppressWarnings("unused")
+ @Past
+ private Date defaultField;
+
+ protected PastValidatorForDate createValidator() {
+ return new PastValidatorForDate();
+ }
+
+ public void testAssertIsValid_nowMinus1000() {
+ assertConstraintValidator(new Date(new Date().getTime() - 1000), true);
+ }
+
+ public void testAssertIsValid_nowPlus1000() {
+ assertConstraintValidator(new Date(new Date().getTime() + 1000), false);
+ }
+
+ @Override
+ protected Class<Past> getAnnotationClass() {
+ return Past.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/PatternValidatorTest.java b/user/test/com/google/gwt/validation/client/constraints/PatternValidatorTest.java
new file mode 100644
index 0000000..f8032e7
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/PatternValidatorTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Pattern;
+
+/**
+ * Tests for {@link PastValidatorForDate}
+ */
+public class PatternValidatorTest extends
+ ConstraintValidatorTestCase<Pattern, String> {
+
+
+ @SuppressWarnings("unused")
+ @Pattern(regexp = "good")
+ private Date defaultField;
+
+ protected PatternValidator createValidator() {
+ return new PatternValidator();
+ }
+
+ public void testAssertIsValid_good() {
+ assertConstraintValidator("this is good", true);
+ }
+
+ public void testAssertIsValid_bad() {
+ assertConstraintValidator("this is bad", false);
+ }
+
+ @Override
+ protected Class<Pattern> getAnnotationClass() {
+ return Pattern.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfBooleanTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfBooleanTest.java
new file mode 100644
index 0000000..d2e6805
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfBooleanTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfBoolean}
+ */
+public class SizeValidatorForArrayOfBooleanTest extends
+ ConstraintValidatorTestCase<Size, boolean[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfBoolean createValidator() {
+ return new SizeValidatorForArrayOfBoolean();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private boolean[] createArray(int size) {
+ boolean[] array = new boolean[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = (i % 2 == 0);
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfByteTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfByteTest.java
new file mode 100644
index 0000000..ee10768
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfByteTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfByte}
+ */
+public class SizeValidatorForArrayOfByteTest extends
+ ConstraintValidatorTestCase<Size, byte[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfByte createValidator() {
+ return new SizeValidatorForArrayOfByte();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private byte[] createArray(int size) {
+ byte[] array = new byte[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = (byte) i;
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfCharTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfCharTest.java
new file mode 100644
index 0000000..38650f6
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfCharTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfChar}
+ */
+public class SizeValidatorForArrayOfCharTest extends
+ ConstraintValidatorTestCase<Size, char[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfChar createValidator() {
+ return new SizeValidatorForArrayOfChar();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private char[] createArray(int size) {
+ char[] array = new char[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = (char) i;
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfDoubleTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfDoubleTest.java
new file mode 100644
index 0000000..c803913
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfDoubleTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfDouble}
+ */
+public class SizeValidatorForArrayOfDoubleTest extends
+ ConstraintValidatorTestCase<Size, double[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfDouble createValidator() {
+ return new SizeValidatorForArrayOfDouble();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private double[] createArray(int size) {
+ double[] array = new double[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = i;
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfFloatTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfFloatTest.java
new file mode 100644
index 0000000..09d5c7f
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfFloatTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfFloat}
+ */
+public class SizeValidatorForArrayOfFloatTest extends
+ ConstraintValidatorTestCase<Size, float[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfFloat createValidator() {
+ return new SizeValidatorForArrayOfFloat();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private float[] createArray(int size) {
+ float[] array = new float[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = i;
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfIntTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfIntTest.java
new file mode 100644
index 0000000..773d44b
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfIntTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfInt}
+ */
+public class SizeValidatorForArrayOfIntTest extends
+ ConstraintValidatorTestCase<Size, int[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfInt createValidator() {
+ return new SizeValidatorForArrayOfInt();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private int[] createArray(int size) {
+ int[] array = new int[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = i;
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfLongTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfLongTest.java
new file mode 100644
index 0000000..4581c8f
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfLongTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfLong}
+ */
+public class SizeValidatorForArrayOfLongTest extends
+ ConstraintValidatorTestCase<Size, long[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfLong createValidator() {
+ return new SizeValidatorForArrayOfLong();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private long[] createArray(int size) {
+ long[] array = new long[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = i;
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfObjectTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfObjectTest.java
new file mode 100644
index 0000000..b62f599
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfObjectTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfObject}
+ */
+public class SizeValidatorForArrayOfObjectTest extends
+ ConstraintValidatorTestCase<Size, Object[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfObject createValidator() {
+ return new SizeValidatorForArrayOfObject();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private Object[] createArray(int size) {
+ Object[] array = new Object[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = Integer.valueOf(i);
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfShortTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfShortTest.java
new file mode 100644
index 0000000..18cf983
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForArrayOfShortTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForArrayOfShort}
+ */
+public class SizeValidatorForArrayOfShortTest extends
+ ConstraintValidatorTestCase<Size, short[]> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForArrayOfShort createValidator() {
+ return new SizeValidatorForArrayOfShort();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createArray(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createArray(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createArray(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createArray(6), false);
+ }
+
+ private short[] createArray(int size) {
+ short[] array = new short[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = (short) i;
+ }
+ return array;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForCollectionTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForCollectionTest.java
new file mode 100644
index 0000000..f8ea8ea
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForCollectionTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForCollection}
+ */
+public class SizeValidatorForCollectionTest extends
+ ConstraintValidatorTestCase<Size, Collection<?>> {
+
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForCollection createValidator() {
+ return new SizeValidatorForCollection();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createList(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createList(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createList(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createList(6), false);
+ }
+
+ private Collection<Integer> createList(int size) {
+ List<Integer> list = new ArrayList<Integer>(size);
+ for (int i = 1; i <= size; i++) {
+ Integer key = Integer.valueOf(i);
+ list.add(key);
+ }
+ return list;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForMapTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForMapTest.java
new file mode 100644
index 0000000..84c63cf
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForMapTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForMap}
+ */
+public class SizeValidatorForMapTest extends
+ ConstraintValidatorTestCase<Size, Map<?, ?>> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForMap createValidator() {
+ return new SizeValidatorForMap();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator(createMap(1), false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator(createMap(2), true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator(createMap(5), true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator(createMap(6), false);
+ }
+
+ private Map<Integer, String> createMap(int size) {
+ Map<Integer, String> map = new HashMap<Integer, String>(size);
+ for (int i = 1; i <= size; i++) {
+ Integer key = Integer.valueOf(i);
+ map.put(key, key.toString());
+ }
+ return map;
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}
diff --git a/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForStringTest.java b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForStringTest.java
new file mode 100644
index 0000000..5687313
--- /dev/null
+++ b/user/test/com/google/gwt/validation/client/constraints/SizeValidatorForStringTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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 com.google.gwt.validation.client.constraints;
+
+import java.util.Date;
+
+import javax.validation.constraints.Size;
+
+/**
+ * Tests for {@link SizeValidatorForString}
+ */
+public class SizeValidatorForStringTest extends
+ ConstraintValidatorTestCase<Size, String> {
+
+ @SuppressWarnings("unused")
+ @Size(min = 2, max = 5)
+ private Date defaultField;
+
+ protected SizeValidatorForString createValidator() {
+ return new SizeValidatorForString();
+ }
+
+ public void testAssertIsValid_short() {
+ assertConstraintValidator("1", false);
+ }
+
+ public void testAssertIsValid_min() {
+ assertConstraintValidator("12", true);
+ }
+
+ public void testAssertIsValid_max() {
+ assertConstraintValidator("12345", true);
+ }
+
+ public void testAssertIsValid_long() {
+ assertConstraintValidator("123456", false);
+ }
+
+ @Override
+ protected Class<Size> getAnnotationClass() {
+ return Size.class;
+ }
+}