This commit is contained in:
Gabriele C 2017-01-29 13:46:52 +01:00
parent 12566f03ef
commit f46dd9445c
2 changed files with 7 additions and 1 deletions

View File

@ -80,7 +80,7 @@ public class ValidationService implements Reloadable {
* @return true if the email is valid, false otherwise * @return true if the email is valid, false otherwise
*/ */
public boolean validateEmail(String email) { public boolean validateEmail(String email) {
if (!email.contains("@") || "your@email.com".equalsIgnoreCase(email)) { if (!email.contains("@") || email.endsWith("@") || "your@email.com".equalsIgnoreCase(email)) {
return false; return false;
} }
final String emailDomain = email.split("@")[1]; final String emailDomain = email.split("@")[1];

View File

@ -187,6 +187,12 @@ public class ValidationServiceTest {
assertThat(validationService.validateEmail("invalidinput"), equalTo(false)); assertThat(validationService.validateEmail("invalidinput"), equalTo(false));
} }
@Test
public void shouldRejectInvalidEmailWithoutDomain() {
// given/when/then
assertThat(validationService.validateEmail("invalidinput@"), equalTo(false));
}
@Test @Test
public void shouldRejectDefaultEmail() { public void shouldRejectDefaultEmail() {
// given/when/then // given/when/then