Browse Source

email validation

feature-pr-notification
Imron 3 years ago
parent
commit
5f23abf6fe
  1. 12
      src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java
  2. 7
      src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java

12
src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java

@ -1,5 +1,7 @@
package hs.fulda.de.ci.exam.project; package hs.fulda.de.ci.exam.project;
import java.util.regex.Pattern;
public class EmailNotification extends Notification { public class EmailNotification extends Notification {
String email; String email;
String content; String content;
@ -19,6 +21,14 @@ public class EmailNotification extends Notification {
} }
private boolean isValidEmail(String email) { private boolean isValidEmail(String email) {
return true;
String regexPattern = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@"
+ "[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";
return patternMatches(email, regexPattern);
}
public static boolean patternMatches(String emailAddress, String regexPattern) {
return Pattern.compile(regexPattern)
.matcher(emailAddress)
.matches();
} }
} }

7
src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java

@ -6,6 +6,13 @@ import static hs.fulda.de.ci.exam.project.ReservationStatus.Confirmed;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class NotificationTest { public class NotificationTest {
@Test
public void emailValidiationShouldReturnTrueForValidEmail(){
EmailNotification email = new EmailNotification("test@gmail.com", "HelloWorld");
boolean result = email.sendNotification();
assertTrue(result);
}
@Test @Test
public void emailNotificationShouldBeSentWhenFlighReservationCompleted() { public void emailNotificationShouldBeSentWhenFlighReservationCompleted() {
FlightReservation reservation = new FlightReservation(); FlightReservation reservation = new FlightReservation();

Loading…
Cancel
Save