-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
140 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
stripes/src/test/java/net/sourceforge/stripes/validation/EmailTypeConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package net.sourceforge.stripes.validation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for the EmailTypeConverter class. Test email address cases taken from <a | ||
* href="https://codefool.tumblr.com/post/15288874550/list-of-valid-and-invalid-email-addresses">here</a>. | ||
*/ | ||
public class EmailTypeConverterTest { | ||
@Test | ||
public void validEmailTests() { | ||
List<String> validEmailAddresses = | ||
List.of( | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"email@[123.123.123.123]", | ||
"\"email\"@example.com", | ||
"johno'[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"much.\"more\\ unusual\"@example.com" | ||
// "very.unusual.\"@\"[email protected]", - Does not pass, and it should | ||
// "very.\"(),:;<>[]\".VERY.\"very@\\\\\\ \"very\"[email protected]" -- Does | ||
// not pass and it should | ||
); | ||
|
||
for (String email : validEmailAddresses) { | ||
TypeConverter<String> converter = new EmailTypeConverter(); | ||
List<ValidationError> errors = new ArrayList<>(); | ||
String result = converter.convert(email, String.class, errors); | ||
Assert.assertEquals(result, email); | ||
Assert.assertEquals( | ||
"Valid email address check failed. Valid Email address was: " + email, 0, errors.size()); | ||
} | ||
} | ||
|
||
@Test | ||
public void invalidEmailTests() { | ||
List<String> invalidEmailAddresses = | ||
List.of( | ||
"plainaddress", | ||
"#@%^%#$@#$@#.com", | ||
"@example.com", | ||
"Joe Smith <[email protected]>", | ||
"email.example.com", | ||
"email@[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"あいうえお@example.com", | ||
"[email protected] (Joe Smith)", | ||
"email@example", | ||
"[email protected]", | ||
// "[email protected]", Should fail even though this is not strict to the old RFC which | ||
// had limited TLDs. | ||
// "[email protected]", Should fail but ignoring because this is going overboard | ||
"[email protected]", | ||
"[email protected]" | ||
// "\"(),:;<>[\\]@example.com", Should fail but ignoring because this is going overboard | ||
// "just\"not\"[email protected]", Should fail but ignoring because this is going | ||
// overboard | ||
// "this\\ is\"really\"not\\\\[email protected]" Should fail but ignoring because this | ||
// is going overboard | ||
); | ||
|
||
for (String email : invalidEmailAddresses) { | ||
TypeConverter<String> converter = new EmailTypeConverter(); | ||
List<ValidationError> errors = new ArrayList<>(); | ||
String result = converter.convert(email, String.class, errors); | ||
Assert.assertEquals(result, email); | ||
Assert.assertEquals( | ||
"Invalid email address check failed. Email address was: " + email, 1, errors.size()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters