summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMikael Grankvist <mgrankvi@vaadin.com>2013-01-11 14:44:33 +0200
committerMikael Grankvist <mgrankvi@vaadin.com>2013-01-11 14:44:33 +0200
commit71b5cce309028033fc5251dc14449ac7f9c0c704 (patch)
treede4152c7afdff2a2ab3ad035ac3849b23e827b8d /server
parent0b6c89db179c03903db2423f4925ad097ce001c7 (diff)
downloadvaadin-framework-71b5cce309028033fc5251dc14449ac7f9c0c704.tar.gz
vaadin-framework-71b5cce309028033fc5251dc14449ac7f9c0c704.zip
(#10561) Email should be valid for null and empty string.
Created tests for email validator. Change-Id: I6be05672ff506247da488ad142f63b7337952bab
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/data/validator/EmailValidator.java14
-rw-r--r--server/tests/src/com/vaadin/tests/data/validator/TestEmailValidator.java26
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"));
+ }
+}