diff --git a/src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java b/src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java index a72d30e..0735a28 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java @@ -5,6 +5,7 @@ import java.util.regex.Pattern; public class EmailNotification extends Notification { String email; String content; + public EmailNotification(String email, String content) { super(); this.email = email; diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java index eaef200..55c0bb8 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java @@ -18,7 +18,7 @@ public class FlightReservation { this.status = status; } - public FlightReservation(){ + public FlightReservation() { } @@ -61,10 +61,15 @@ public class FlightReservation { status = Confirmed; } - public boolean notifyUser(String type, String email, String content) { + public boolean notifyUser(String type, String to, String content) { Notification notification = null; switch (type) { - case "email": notification = new EmailNotification(email, content); + case "email": + notification = new EmailNotification(to, content); + break; + case "sms": + notification = new SmsNotification(to, content); + break; } return notification.sendNotification(); } 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 new file mode 100644 index 0000000..82529d6 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java @@ -0,0 +1,12 @@ +package hs.fulda.de.ci.exam.project; + +public class SmsNotification extends Notification { + public SmsNotification(String to, String content) { + super(); + } + + @Override + public boolean sendNotification() { + 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 2c2fced..579666f 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 @@ -7,14 +7,14 @@ import static org.junit.jupiter.api.Assertions.*; public class NotificationTest { @Test - public void emailValidiationShouldReturnTrueForValidEmail(){ + public void emailValidiationShouldReturnTrueForValidEmail() { EmailNotification email = new EmailNotification("test@gmail.com", "HelloWorld"); boolean result = email.sendNotification(); assertTrue(result); } @Test - public void emailValidiationShouldReturnFalseForInValidEmail(){ + public void emailValidiationShouldReturnFalseForInValidEmail() { EmailNotification email = new EmailNotification("testgmail.com", "HelloWorld"); boolean result = email.sendNotification(); assertFalse(result); @@ -24,7 +24,15 @@ public class NotificationTest { public void emailNotificationShouldBeSentWhenFlighReservationCompleted() { FlightReservation reservation = new FlightReservation(); reservation.setStatus(Confirmed); - boolean result = reservation.notifyUser("email", "test@gmail.com","Reservation is Confirmed!"); + boolean result = reservation.notifyUser("email", "test@gmail.com", "Reservation is Confirmed!"); + assertTrue(result); + } + + @Test + public void smsNotificationShouldBeSentWhenSmsTypeIsChosen(){ + FlightReservation reservation = new FlightReservation(); + reservation.setStatus(Confirmed); + boolean result = reservation.notifyUser("sms", "01788370107", "Reservation is successfull"); assertTrue(result); } }