Browse Source

sms validation for false number

feature-pr-notification
Imron 3 years ago
parent
commit
e5dcacd334
  1. 14
      src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java
  2. 7
      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();
}
}

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

@ -42,4 +42,11 @@ public class NotificationTest {
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