]> source.dussan.org Git - vaadin-framework.git/commitdiff
(#10561) Email should be valid for null and empty string. 30/630/1
authorMikael Grankvist <mgrankvi@vaadin.com>
Fri, 11 Jan 2013 12:44:33 +0000 (14:44 +0200)
committerMikael Grankvist <mgrankvi@vaadin.com>
Fri, 11 Jan 2013 12:44:33 +0000 (14:44 +0200)
Created tests for email validator.

Change-Id: I6be05672ff506247da488ad142f63b7337952bab

server/src/com/vaadin/data/validator/EmailValidator.java
server/tests/src/com/vaadin/tests/data/validator/TestEmailValidator.java [new file with mode: 0644]

index 5985abf2cfdf42d98a3e6a977eec2d5e9cf938a5..2217b3cf2c5f392f229980ef8ea257f8ede371a9 100644 (file)
@@ -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 (file)
index 0000000..7644b47
--- /dev/null
@@ -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"));
+    }
+}