From f4c587cf42fe0cfb0b2838637fab9f52caa42364 Mon Sep 17 00:00:00 2001 From: Imron Date: Wed, 16 Feb 2022 13:14:35 +0100 Subject: [PATCH] sms validation --- .../fulda/de/ci/exam/project/SmsNotification.java | 13 +++++++++++++ .../fulda/de/ci/exam/project/NotificationTest.java | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java b/src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java index 82529d6..2be45eb 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java @@ -1,12 +1,25 @@ package hs.fulda.de.ci.exam.project; public class SmsNotification extends Notification { + String to; + String content; public SmsNotification(String to, String content) { super(); + this.to = to; + this.content = content; } @Override public boolean sendNotification() { + if (isValidEmail(to)) { + System.out.println("SMS is sent to " + to); + return true; + } + System.out.println("Invalid Number"); + return false; + } + + private boolean isValidEmail(String to) { return true; } } diff --git a/src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java b/src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java index 579666f..b57b57f 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java @@ -35,4 +35,11 @@ public class NotificationTest { boolean result = reservation.notifyUser("sms", "01788370107", "Reservation is successfull"); assertTrue(result); } + + @Test + public void smsIsSentWhenNumberIsValid(){ + SmsNotification sms = new SmsNotification("01788370107", "Reservation confirmed"); + boolean result = sms.sendNotification(); + assertTrue(result); + } }