Browse Source

sms notification

feature-pr-notification
Imron 3 years ago
parent
commit
7abce6392e
  1. 1
      src/main/java/hs/fulda/de/ci/exam/project/EmailNotification.java
  2. 11
      src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java
  3. 12
      src/main/java/hs/fulda/de/ci/exam/project/SmsNotification.java
  4. 14
      src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java

1
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 { public class EmailNotification extends Notification {
String email; String email;
String content; String content;
public EmailNotification(String email, String content) { public EmailNotification(String email, String content) {
super(); super();
this.email = email; this.email = email;

11
src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java

@ -18,7 +18,7 @@ public class FlightReservation {
this.status = status; this.status = status;
} }
public FlightReservation(){
public FlightReservation() {
} }
@ -61,10 +61,15 @@ public class FlightReservation {
status = Confirmed; status = Confirmed;
} }
public boolean notifyUser(String type, String email, String content) {
public boolean notifyUser(String type, String to, String content) {
Notification notification = null; Notification notification = null;
switch (type) { 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(); return notification.sendNotification();
} }

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

14
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 { public class NotificationTest {
@Test @Test
public void emailValidiationShouldReturnTrueForValidEmail(){
public void emailValidiationShouldReturnTrueForValidEmail() {
EmailNotification email = new EmailNotification("test@gmail.com", "HelloWorld"); EmailNotification email = new EmailNotification("test@gmail.com", "HelloWorld");
boolean result = email.sendNotification(); boolean result = email.sendNotification();
assertTrue(result); assertTrue(result);
} }
@Test @Test
public void emailValidiationShouldReturnFalseForInValidEmail(){
public void emailValidiationShouldReturnFalseForInValidEmail() {
EmailNotification email = new EmailNotification("testgmail.com", "HelloWorld"); EmailNotification email = new EmailNotification("testgmail.com", "HelloWorld");
boolean result = email.sendNotification(); boolean result = email.sendNotification();
assertFalse(result); assertFalse(result);
@ -24,7 +24,15 @@ public class NotificationTest {
public void emailNotificationShouldBeSentWhenFlighReservationCompleted() { public void emailNotificationShouldBeSentWhenFlighReservationCompleted() {
FlightReservation reservation = new FlightReservation(); FlightReservation reservation = new FlightReservation();
reservation.setStatus(Confirmed); 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); assertTrue(result);
} }
} }
Loading…
Cancel
Save