Browse Source

email notification

feature-pr-notification
Imron 3 years ago
parent
commit
8277f7fb60
  1. 24
      src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java
  2. 8
      src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java
  3. 5
      src/main/java/hs/fulda/de/ci/exam/project/Notification.java
  4. 16
      src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java

24
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;
}
}

8
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();
}
}

5
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();
}

16
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);
}
}
Loading…
Cancel
Save