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/tests/src | |
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/tests/src')
6 files changed, 302 insertions, 0 deletions
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)); + } +} |