diff options
-rw-r--r-- | server/src/com/vaadin/data/validator/EmailValidator.java | 14 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/data/validator/TestEmailValidator.java | 26 |
2 files changed, 40 insertions, 0 deletions
diff --git a/server/src/com/vaadin/data/validator/EmailValidator.java b/server/src/com/vaadin/data/validator/EmailValidator.java index 5985abf2cf..2217b3cf2c 100644 --- a/server/src/com/vaadin/data/validator/EmailValidator.java +++ b/server/src/com/vaadin/data/validator/EmailValidator.java @@ -42,4 +42,18 @@ public class EmailValidator extends RegexpValidator { true, errorMessage); } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.data.validator.AbstractValidator#isValidValue(java.lang.Object + * ) + */ + @Override + protected boolean isValidValue(String value) { + if (value == null || value.isEmpty()) { + return true; + } + return super.isValidValue(value); + } } diff --git a/server/tests/src/com/vaadin/tests/data/validator/TestEmailValidator.java b/server/tests/src/com/vaadin/tests/data/validator/TestEmailValidator.java new file mode 100644 index 0000000000..7644b4738c --- /dev/null +++ b/server/tests/src/com/vaadin/tests/data/validator/TestEmailValidator.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.data.validator; + +import junit.framework.TestCase; + +import com.vaadin.data.validator.EmailValidator; + +public class TestEmailValidator extends TestCase { + + private EmailValidator validator = new EmailValidator("Error"); + + public void testEmailValidatorWithNull() { + assertTrue(validator.isValid(null)); + } + + public void testEmailValidatorWithEmptyString() { + assertTrue(validator.isValid("")); + } + + public void testEmailValidatorWithFaultyString() { + assertFalse(validator.isValid("not.an.email")); + } + + public void testEmailValidatorWithOkEmail() { + assertTrue(validator.isValid("my.name@email.com")); + } +} |