From 8277f7fb6078e8ef76b67547e2bbfcbf7c64c432 Mon Sep 17 00:00:00 2001 From: Imron Date: Wed, 16 Feb 2022 12:52:07 +0100 Subject: [PATCH] email notification --- .../de/ci/exam/project/EmailNotification.java | 24 +++++++++++++++++++ .../de/ci/exam/project/FlightReservation.java | 8 +++++++ .../de/ci/exam/project/Notification.java | 5 ++++ .../de/ci/exam/project/NotificationTest.java | 16 +++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/Notification.java create mode 100644 src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java 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 new file mode 100644 index 0000000..ca37a9d --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java @@ -0,0 +1,24 @@ +package hs.fulda.de.ci.exam.project; + +public class EmailNotification extends Notification { + String email; + String content; + public EmailNotification(String email, String content) { + super(); + this.email = email; + this.content = content; + } + + @Override + public boolean sendNotification() { + if (isValidEmail(email)) { + System.out.println("Email is sent to " + email); + return true; + } + return false; + } + + private boolean isValidEmail(String email) { + return true; + } +} 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 f288009..eaef200 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 @@ -60,4 +60,12 @@ public class FlightReservation { credit_card_payment.status = Completed; status = Confirmed; } + + public boolean notifyUser(String type, String email, String content) { + Notification notification = null; + switch (type) { + case "email": notification = new EmailNotification(email, content); + } + return notification.sendNotification(); + } } diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Notification.java b/src/main/java/hs/fulda/de/ci/exam/project/Notification.java new file mode 100644 index 0000000..4821060 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/Notification.java @@ -0,0 +1,5 @@ +package hs.fulda.de.ci.exam.project; + +public abstract class Notification { + public abstract boolean sendNotification(); +} 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 new file mode 100644 index 0000000..a23b63b --- /dev/null +++ b/src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java @@ -0,0 +1,16 @@ +package hs.fulda.de.ci.exam.project; + +import org.junit.Test; + +import static hs.fulda.de.ci.exam.project.ReservationStatus.Confirmed; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class NotificationTest { + @Test + public void emailNotificationShouldBeSentWhenFlighReservationCompleted() { + FlightReservation reservation = new FlightReservation(); + reservation.setStatus(Confirmed); + boolean result = reservation.notifyUser("email", "test@gmail.com","Reservation is Confirmed!"); + assertTrue(result); + } +}