|
@ -3,50 +3,58 @@ package hs.fulda.de.ci.exam.project; |
|
|
import org.junit.Test; |
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
import static hs.fulda.de.ci.exam.project.ReservationStatus.Confirmed; |
|
|
import static hs.fulda.de.ci.exam.project.ReservationStatus.Confirmed; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
|
public class NotificationTest { |
|
|
public class NotificationTest { |
|
|
|
|
|
|
|
|
|
|
|
EmailNotification email = new EmailNotification("test@gmail.com", "HelloWorld"); |
|
|
|
|
|
EmailNotification emailInvalid = new EmailNotification("testgmail.com", "HelloWorld"); |
|
|
|
|
|
FlightReservation reservation = new FlightReservation(); |
|
|
|
|
|
SmsNotification sms = new SmsNotification("01788370107", "Reservation confirmed"); |
|
|
|
|
|
SmsNotification smsInvalid = new SmsNotification("123", "Some Wrong Number"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void emailValidiationShouldReturnTrueForValidEmail() { |
|
|
public void emailValidiationShouldReturnTrueForValidEmail() { |
|
|
EmailNotification email = new EmailNotification("test@gmail.com", "HelloWorld"); |
|
|
|
|
|
boolean result = email.sendNotification(); |
|
|
boolean result = email.sendNotification(); |
|
|
assertTrue(result); |
|
|
|
|
|
|
|
|
boolean expected = true; |
|
|
|
|
|
assertThat(expected).isEqualTo(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void emailValidiationShouldReturnFalseForInValidEmail() { |
|
|
public void emailValidiationShouldReturnFalseForInValidEmail() { |
|
|
EmailNotification email = new EmailNotification("testgmail.com", "HelloWorld"); |
|
|
|
|
|
boolean result = email.sendNotification(); |
|
|
|
|
|
assertFalse(result); |
|
|
|
|
|
|
|
|
boolean result = emailInvalid.sendNotification(); |
|
|
|
|
|
boolean expected = false; |
|
|
|
|
|
assertThat(expected).isEqualTo(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void emailNotificationShouldBeSentWhenFlighReservationCompleted() { |
|
|
public void emailNotificationShouldBeSentWhenFlighReservationCompleted() { |
|
|
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); |
|
|
|
|
|
|
|
|
boolean expected = true; |
|
|
|
|
|
assertThat(expected).isEqualTo(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void smsNotificationShouldBeSentWhenSmsTypeIsChosen() { |
|
|
public void smsNotificationShouldBeSentWhenSmsTypeIsChosen() { |
|
|
FlightReservation reservation = new FlightReservation(); |
|
|
|
|
|
reservation.setStatus(Confirmed); |
|
|
reservation.setStatus(Confirmed); |
|
|
boolean result = reservation.notifyUser("sms", "01788370107", "Reservation is successfull"); |
|
|
boolean result = reservation.notifyUser("sms", "01788370107", "Reservation is successfull"); |
|
|
assertTrue(result); |
|
|
|
|
|
|
|
|
boolean expected = true; |
|
|
|
|
|
assertThat(expected).isEqualTo(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void smsIsSentWhenNumberIsValid() { |
|
|
public void smsIsSentWhenNumberIsValid() { |
|
|
SmsNotification sms = new SmsNotification("01788370107", "Reservation confirmed"); |
|
|
|
|
|
boolean result = sms.sendNotification(); |
|
|
boolean result = sms.sendNotification(); |
|
|
assertTrue(result); |
|
|
|
|
|
|
|
|
boolean expected = true; |
|
|
|
|
|
assertThat(expected).isEqualTo(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void smsShouldNotBeSentWhenNumberIsInvalid() { |
|
|
public void smsShouldNotBeSentWhenNumberIsInvalid() { |
|
|
SmsNotification sms = new SmsNotification("123", "Some Wrong Number"); |
|
|
|
|
|
boolean result = sms.sendNotification(); |
|
|
|
|
|
assertFalse(result); |
|
|
|
|
|
|
|
|
boolean result = smsInvalid.sendNotification(); |
|
|
|
|
|
boolean expected = false; |
|
|
|
|
|
assertThat(expected).isEqualTo(result); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |