diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-01-11 13:25:39 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-01-11 13:25:39 +0000 |
commit | d2e7755d0da19c20c172a88271b14514ce8bcdb3 (patch) | |
tree | 87714598c4256ecff0587cab051715594dd8623a | |
parent | 33b719ac5ab2203c84002e44375c8d218ddbaa35 (diff) | |
parent | 71b5cce309028033fc5251dc14449ac7f9c0c704 (diff) | |
download | vaadin-framework-d2e7755d0da19c20c172a88271b14514ce8bcdb3.tar.gz vaadin-framework-d2e7755d0da19c20c172a88271b14514ce8bcdb3.zip |
Merge "(#10561) Email should be valid for null and empty string. Created tests for email validator."
-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")); + } +} |