diff options
author | denis.magdenkov <denis.magdenkov@arcadia.spb.ru> | 2014-09-06 15:58:25 +0400 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-09-17 10:10:16 +0000 |
commit | ca7dfd60d66bfdf32a15eccd6c7b5ae62baba39c (patch) | |
tree | 2007c096164c95a6b1566e1e5b68c97360104ebd /server | |
parent | a8d2a80d467343a73857b28ea813090ecae11fdf (diff) | |
download | vaadin-framework-ca7dfd60d66bfdf32a15eccd6c7b5ae62baba39c.tar.gz vaadin-framework-ca7dfd60d66bfdf32a15eccd6c7b5ae62baba39c.zip |
Add Range<Byte, Short, Long, Float, BigInteger, BigDecimal> Validators (#14584)
Fix code review points.
Change-Id: Ia1ef55ff7ef806f9b71cb97f8f09bd4c6ec97a41
Diffstat (limited to 'server')
12 files changed, 588 insertions, 0 deletions
diff --git a/server/src/com/vaadin/data/validator/BigDecimalRangeValidator.java b/server/src/com/vaadin/data/validator/BigDecimalRangeValidator.java new file mode 100644 index 0000000000..9b1d2bb565 --- /dev/null +++ b/server/src/com/vaadin/data/validator/BigDecimalRangeValidator.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * 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.vaadin.data.validator; + +import java.math.BigDecimal; + +/** + * Validator for validating that an {@link BigDecimal} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class BigDecimalRangeValidator extends RangeValidator<BigDecimal> { + + /** + * Creates a validator for checking that an BigDecimal is within a given + * range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public BigDecimalRangeValidator(String errorMessage, BigDecimal minValue, + BigDecimal maxValue) { + super(errorMessage, BigDecimal.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/BigIntegerRangeValidator.java b/server/src/com/vaadin/data/validator/BigIntegerRangeValidator.java new file mode 100644 index 0000000000..bfe9dadc3f --- /dev/null +++ b/server/src/com/vaadin/data/validator/BigIntegerRangeValidator.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * 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.vaadin.data.validator; + +import java.math.BigInteger; + +/** + * Validator for validating that an {@link BigInteger} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class BigIntegerRangeValidator extends RangeValidator<BigInteger> { + + /** + * Creates a validator for checking that an BigInteger is within a given + * range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public BigIntegerRangeValidator(String errorMessage, BigInteger minValue, + BigInteger maxValue) { + super(errorMessage, BigInteger.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/ByteRangeValidator.java b/server/src/com/vaadin/data/validator/ByteRangeValidator.java new file mode 100644 index 0000000000..c09a290d8a --- /dev/null +++ b/server/src/com/vaadin/data/validator/ByteRangeValidator.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * 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.vaadin.data.validator; + +/** + * Validator for validating that an {@link Byte} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class ByteRangeValidator extends RangeValidator<Byte> { + + /** + * Creates a validator for checking that an Byte is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public ByteRangeValidator(String errorMessage, Byte minValue, Byte maxValue) { + super(errorMessage, Byte.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/FloatRangeValidator.java b/server/src/com/vaadin/data/validator/FloatRangeValidator.java new file mode 100644 index 0000000000..903c8c475f --- /dev/null +++ b/server/src/com/vaadin/data/validator/FloatRangeValidator.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * 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.vaadin.data.validator; + +/** + * Validator for validating that a {@link Float} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class FloatRangeValidator extends RangeValidator<Float> { + + /** + * Creates a validator for checking that an Float is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public FloatRangeValidator(String errorMessage, Float minValue, + Float maxValue) { + super(errorMessage, Float.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/LongRangeValidator.java b/server/src/com/vaadin/data/validator/LongRangeValidator.java new file mode 100644 index 0000000000..829b37e37b --- /dev/null +++ b/server/src/com/vaadin/data/validator/LongRangeValidator.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * 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.vaadin.data.validator; + +/** + * Validator for validating that an {@link Long} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class LongRangeValidator extends RangeValidator<Long> { + + /** + * Creates a validator for checking that an Long is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public LongRangeValidator(String errorMessage, Long minValue, Long maxValue) { + super(errorMessage, Long.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/ShortRangeValidator.java b/server/src/com/vaadin/data/validator/ShortRangeValidator.java new file mode 100644 index 0000000000..70e0b7c1e8 --- /dev/null +++ b/server/src/com/vaadin/data/validator/ShortRangeValidator.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * 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.vaadin.data.validator; + +/** + * Validator for validating that an {@link Short} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class ShortRangeValidator extends RangeValidator<Short> { + + /** + * Creates a validator for checking that an Short is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public ShortRangeValidator(String errorMessage, Short minValue, + Short maxValue) { + super(errorMessage, Short.class, minValue, maxValue); + } + +} diff --git a/server/tests/src/com/vaadin/tests/data/validator/TestBigDecimalRangeValidator.java b/server/tests/src/com/vaadin/tests/data/validator/TestBigDecimalRangeValidator.java new file mode 100644 index 0000000000..2ce576fb77 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/data/validator/TestBigDecimalRangeValidator.java @@ -0,0 +1,55 @@ +package com.vaadin.tests.data.validator; + +import java.math.BigDecimal; + +import junit.framework.TestCase; + +import com.vaadin.data.validator.BigDecimalRangeValidator; + +public class TestBigDecimalRangeValidator extends TestCase { + + private BigDecimalRangeValidator cleanValidator = new BigDecimalRangeValidator( + "no values", null, null); + private BigDecimalRangeValidator minValidator = new BigDecimalRangeValidator( + "no values", new BigDecimal(10.1), null); + private BigDecimalRangeValidator maxValidator = new BigDecimalRangeValidator( + "no values", null, new BigDecimal(100.1)); + private BigDecimalRangeValidator minMaxValidator = new BigDecimalRangeValidator( + "no values", new BigDecimal(10.5), new BigDecimal(100.5)); + + public void testNullValue() { + assertTrue("Didn't accept null", cleanValidator.isValid(null)); + assertTrue("Didn't accept null", minValidator.isValid(null)); + assertTrue("Didn't accept null", maxValidator.isValid(null)); + assertTrue("Didn't accept null", minMaxValidator.isValid(null)); + } + + public void testMinValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(new BigDecimal(-15.0))); + assertTrue("Didn't accept valid value", + minValidator.isValid(new BigDecimal(10.1))); + assertFalse("Accepted too small value", + minValidator.isValid(new BigDecimal(10.0))); + } + + public void testMaxValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(new BigDecimal(1120.0))); + assertTrue("Didn't accept valid value", + maxValidator.isValid(new BigDecimal(15.0))); + assertFalse("Accepted too large value", + maxValidator.isValid(new BigDecimal(100.6))); + } + + public void testMinMaxValue() { + assertTrue("Didn't accept valid value", + minMaxValidator.isValid(new BigDecimal(10.5))); + assertTrue("Didn't accept valid value", + minMaxValidator.isValid(new BigDecimal(100.5))); + assertFalse("Accepted too small value", + minMaxValidator.isValid(new BigDecimal(10.4))); + assertFalse("Accepted too large value", + minMaxValidator.isValid(new BigDecimal(100.6))); + } +} diff --git a/server/tests/src/com/vaadin/tests/data/validator/TestBigIntegerRangeValidator.java b/server/tests/src/com/vaadin/tests/data/validator/TestBigIntegerRangeValidator.java new file mode 100644 index 0000000000..d3263df6d2 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/data/validator/TestBigIntegerRangeValidator.java @@ -0,0 +1,55 @@ +package com.vaadin.tests.data.validator; + +import java.math.BigInteger; + +import junit.framework.TestCase; + +import com.vaadin.data.validator.BigIntegerRangeValidator; + +public class TestBigIntegerRangeValidator extends TestCase { + + private BigIntegerRangeValidator cleanValidator = new BigIntegerRangeValidator( + "no values", null, null); + private BigIntegerRangeValidator minValidator = new BigIntegerRangeValidator( + "no values", BigInteger.valueOf(10), null); + private BigIntegerRangeValidator maxValidator = new BigIntegerRangeValidator( + "no values", null, BigInteger.valueOf(100)); + private BigIntegerRangeValidator minMaxValidator = new BigIntegerRangeValidator( + "no values", BigInteger.valueOf(10), BigInteger.valueOf(100)); + + public void testNullValue() { + assertTrue("Didn't accept null", cleanValidator.isValid(null)); + assertTrue("Didn't accept null", minValidator.isValid(null)); + assertTrue("Didn't accept null", maxValidator.isValid(null)); + assertTrue("Didn't accept null", minMaxValidator.isValid(null)); + } + + public void testMinValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(BigInteger.valueOf(-15))); + assertTrue("Didn't accept valid value", + minValidator.isValid(BigInteger.valueOf(15))); + assertFalse("Accepted too small value", + minValidator.isValid(BigInteger.valueOf(9))); + } + + public void testMaxValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(BigInteger.valueOf(1120))); + assertTrue("Didn't accept valid value", + maxValidator.isValid(BigInteger.valueOf(15))); + assertFalse("Accepted too large value", + maxValidator.isValid(BigInteger.valueOf(120))); + } + + public void testMinMaxValue() { + assertTrue("Didn't accept valid value", + minMaxValidator.isValid(BigInteger.valueOf(15))); + assertTrue("Didn't accept valid value", + minMaxValidator.isValid(BigInteger.valueOf(99))); + assertFalse("Accepted too small value", + minMaxValidator.isValid(BigInteger.valueOf(9))); + assertFalse("Accepted too large value", + minMaxValidator.isValid(BigInteger.valueOf(110))); + } +} diff --git a/server/tests/src/com/vaadin/tests/data/validator/TestByteRangeValidator.java b/server/tests/src/com/vaadin/tests/data/validator/TestByteRangeValidator.java new file mode 100644 index 0000000000..6fac06c31b --- /dev/null +++ b/server/tests/src/com/vaadin/tests/data/validator/TestByteRangeValidator.java @@ -0,0 +1,50 @@ +package com.vaadin.tests.data.validator; + +import junit.framework.TestCase; + +import com.vaadin.data.validator.ByteRangeValidator; + +public class TestByteRangeValidator extends TestCase { + + private ByteRangeValidator cleanValidator = new ByteRangeValidator( + "no values", null, null); + private ByteRangeValidator minValidator = new ByteRangeValidator( + "no values", (byte) 10, null); + private ByteRangeValidator maxValidator = new ByteRangeValidator( + "no values", null, (byte) 100); + private ByteRangeValidator minMaxValidator = new ByteRangeValidator( + "no values", (byte) 10, (byte) 100); + + public void testNullValue() { + assertTrue("Didn't accept null", cleanValidator.isValid(null)); + assertTrue("Didn't accept null", minValidator.isValid(null)); + assertTrue("Didn't accept null", maxValidator.isValid(null)); + assertTrue("Didn't accept null", minMaxValidator.isValid(null)); + } + + public void testMinValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid((byte) -15)); + assertTrue("Didn't accept valid value", minValidator.isValid((byte) 15)); + assertFalse("Accepted too small value", minValidator.isValid((byte) 9)); + } + + public void testMaxValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid((byte) 112)); + assertTrue("Didn't accept valid value", maxValidator.isValid((byte) 15)); + assertFalse("Accepted too large value", + maxValidator.isValid((byte) 120)); + } + + public void testMinMaxValue() { + assertTrue("Didn't accept valid value", + minMaxValidator.isValid((byte) 15)); + assertTrue("Didn't accept valid value", + minMaxValidator.isValid((byte) 99)); + assertFalse("Accepted too small value", + minMaxValidator.isValid((byte) 9)); + assertFalse("Accepted too large value", + minMaxValidator.isValid((byte) 110)); + } +} diff --git a/server/tests/src/com/vaadin/tests/data/validator/TestFloatRangeValidator.java b/server/tests/src/com/vaadin/tests/data/validator/TestFloatRangeValidator.java new file mode 100644 index 0000000000..8de363e3d7 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/data/validator/TestFloatRangeValidator.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.data.validator; + +import junit.framework.TestCase; + +import com.vaadin.data.validator.FloatRangeValidator; + +public class TestFloatRangeValidator extends TestCase { + + private FloatRangeValidator cleanValidator = new FloatRangeValidator( + "no values", null, null); + private FloatRangeValidator minValidator = new FloatRangeValidator( + "no values", 10.1f, null); + private FloatRangeValidator maxValidator = new FloatRangeValidator( + "no values", null, 100.1f); + private FloatRangeValidator minMaxValidator = new FloatRangeValidator( + "no values", 10.5f, 100.5f); + + public void testNullValue() { + assertTrue("Didn't accept null", cleanValidator.isValid(null)); + assertTrue("Didn't accept null", minValidator.isValid(null)); + assertTrue("Didn't accept null", maxValidator.isValid(null)); + assertTrue("Didn't accept null", minMaxValidator.isValid(null)); + } + + public void testMinValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(-15.0f)); + assertTrue("Didn't accept valid value", minValidator.isValid(10.1f)); + assertFalse("Accepted too small value", minValidator.isValid(10.0f)); + } + + public void testMaxValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(1120.0f)); + assertTrue("Didn't accept valid value", maxValidator.isValid(15.0f)); + assertFalse("Accepted too large value", maxValidator.isValid(100.6f)); + } + + public void testMinMaxValue() { + assertTrue("Didn't accept valid value", minMaxValidator.isValid(10.5f)); + assertTrue("Didn't accept valid value", minMaxValidator.isValid(100.5f)); + assertFalse("Accepted too small value", minMaxValidator.isValid(10.4f)); + assertFalse("Accepted too large value", minMaxValidator.isValid(100.6f)); + } +} diff --git a/server/tests/src/com/vaadin/tests/data/validator/TestLongRangeValidator.java b/server/tests/src/com/vaadin/tests/data/validator/TestLongRangeValidator.java new file mode 100644 index 0000000000..a9aeb6b67b --- /dev/null +++ b/server/tests/src/com/vaadin/tests/data/validator/TestLongRangeValidator.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.data.validator; + +import junit.framework.TestCase; + +import com.vaadin.data.validator.LongRangeValidator; + +public class TestLongRangeValidator extends TestCase { + + private LongRangeValidator cleanValidator = new LongRangeValidator( + "no values", null, null); + private LongRangeValidator minValidator = new LongRangeValidator( + "no values", 10l, null); + private LongRangeValidator maxValidator = new LongRangeValidator( + "no values", null, 100l); + private LongRangeValidator minMaxValidator = new LongRangeValidator( + "no values", 10l, 100l); + + public void testNullValue() { + assertTrue("Didn't accept null", cleanValidator.isValid(null)); + assertTrue("Didn't accept null", minValidator.isValid(null)); + assertTrue("Didn't accept null", maxValidator.isValid(null)); + assertTrue("Didn't accept null", minMaxValidator.isValid(null)); + } + + public void testMinValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(-15l)); + assertTrue("Didn't accept valid value", minValidator.isValid(15l)); + assertFalse("Accepted too small value", minValidator.isValid(9l)); + } + + public void testMaxValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid(1120l)); + assertTrue("Didn't accept valid value", maxValidator.isValid(15l)); + assertFalse("Accepted too large value", maxValidator.isValid(120l)); + } + + public void testMinMaxValue() { + assertTrue("Didn't accept valid value", minMaxValidator.isValid(15l)); + assertTrue("Didn't accept valid value", minMaxValidator.isValid(99l)); + assertFalse("Accepted too small value", minMaxValidator.isValid(9l)); + assertFalse("Accepted too large value", minMaxValidator.isValid(110l)); + } +} diff --git a/server/tests/src/com/vaadin/tests/data/validator/TestShortRangeValidator.java b/server/tests/src/com/vaadin/tests/data/validator/TestShortRangeValidator.java new file mode 100644 index 0000000000..b522abb179 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/data/validator/TestShortRangeValidator.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.data.validator; + +import junit.framework.TestCase; + +import com.vaadin.data.validator.ShortRangeValidator; + +public class TestShortRangeValidator extends TestCase { + + private ShortRangeValidator cleanValidator = new ShortRangeValidator( + "no values", null, null); + private ShortRangeValidator minValidator = new ShortRangeValidator( + "no values", (short) 10, null); + private ShortRangeValidator maxValidator = new ShortRangeValidator( + "no values", null, (short) 100); + private ShortRangeValidator minMaxValidator = new ShortRangeValidator( + "no values", (short) 10, (short) 100); + + public void testNullValue() { + assertTrue("Didn't accept null", cleanValidator.isValid(null)); + assertTrue("Didn't accept null", minValidator.isValid(null)); + assertTrue("Didn't accept null", maxValidator.isValid(null)); + assertTrue("Didn't accept null", minMaxValidator.isValid(null)); + } + + public void testMinValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid((short) -15)); + assertTrue("Didn't accept valid value", + minValidator.isValid((short) 15)); + assertFalse("Accepted too small value", minValidator.isValid((short) 9)); + } + + public void testMaxValue() { + assertTrue("Validator without ranges didn't accept value", + cleanValidator.isValid((short) 1120)); + assertTrue("Didn't accept valid value", + maxValidator.isValid((short) 15)); + assertFalse("Accepted too large value", + maxValidator.isValid((short) 120)); + } + + public void testMinMaxValue() { + assertTrue("Didn't accept valid value", + minMaxValidator.isValid((short) 15)); + assertTrue("Didn't accept valid value", + minMaxValidator.isValid((short) 99)); + assertFalse("Accepted too small value", + minMaxValidator.isValid((short) 9)); + assertFalse("Accepted too large value", + minMaxValidator.isValid((short) 110)); + } +} |