Browse Source

refactor tests

feature-pr-notification
Imron 3 years ago
parent
commit
38cdbc8fbb
  1. 38
      src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java

38
src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java

@ -3,50 +3,58 @@ 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.*;
import static org.assertj.core.api.Assertions.assertThat;
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
public void emailValidiationShouldReturnTrueForValidEmail() {
EmailNotification email = new EmailNotification("test@gmail.com", "HelloWorld");
boolean result = email.sendNotification();
assertTrue(result);
boolean expected = true;
assertThat(expected).isEqualTo(result);
}
@Test
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
public void emailNotificationShouldBeSentWhenFlighReservationCompleted() {
FlightReservation reservation = new FlightReservation();
reservation.setStatus(Confirmed);
boolean result = reservation.notifyUser("email", "test@gmail.com", "Reservation is Confirmed!");
assertTrue(result);
boolean expected = true;
assertThat(expected).isEqualTo(result);
}
@Test
public void smsNotificationShouldBeSentWhenSmsTypeIsChosen() {
FlightReservation reservation = new FlightReservation();
reservation.setStatus(Confirmed);
boolean result = reservation.notifyUser("sms", "01788370107", "Reservation is successfull");
assertTrue(result);
boolean expected = true;
assertThat(expected).isEqualTo(result);
}
@Test
public void smsIsSentWhenNumberIsValid() {
SmsNotification sms = new SmsNotification("01788370107", "Reservation confirmed");
boolean result = sms.sendNotification();
assertTrue(result);
boolean expected = true;
assertThat(expected).isEqualTo(result);
}
@Test
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);
}
}
Loading…
Cancel
Save