Browse Source

sms validation for false number

feature-pr-notification
Imron 2 years ago
parent
commit
e5dcacd334
  1. 14
      src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java
  2. 11
      src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java

14
src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java

@ -1,8 +1,11 @@
package hs.fulda.de.ci.exam.project;
import java.util.regex.Pattern;
public class SmsNotification extends Notification {
String to;
String content;
public SmsNotification(String to, String content) {
super();
this.to = to;
@ -20,6 +23,15 @@ public class SmsNotification extends Notification {
}
private boolean isValidEmail(String to) {
return true;
String regexPattern = "(\\(?([\\d \\-\\)\\–\\+\\/\\(]+){6,}\\)?([ .\\-–\\/]?)([\\d]+))";
return patternMatches(to, regexPattern);
}
public static boolean patternMatches(String emailAddress, String regexPattern) {
return Pattern.compile(regexPattern)
.matcher(emailAddress)
.matches();
}
}

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

@ -29,7 +29,7 @@ public class NotificationTest {
}
@Test
public void smsNotificationShouldBeSentWhenSmsTypeIsChosen(){
public void smsNotificationShouldBeSentWhenSmsTypeIsChosen() {
FlightReservation reservation = new FlightReservation();
reservation.setStatus(Confirmed);
boolean result = reservation.notifyUser("sms", "01788370107", "Reservation is successfull");
@ -37,9 +37,16 @@ public class NotificationTest {
}
@Test
public void smsIsSentWhenNumberIsValid(){
public void smsIsSentWhenNumberIsValid() {
SmsNotification sms = new SmsNotification("01788370107", "Reservation confirmed");
boolean result = sms.sendNotification();
assertTrue(result);
}
@Test
public void smsShouldNotBeSentWhenNumberIsInvalid() {
SmsNotification sms = new SmsNotification("123", "Some Wrong Number");
boolean result = sms.sendNotification();
assertFalse(result);
}
}
Loading…
Cancel
Save