From 38cdbc8fbb2753edb07ebd58b1d01be5882d7ae7 Mon Sep 17 00:00:00 2001 From: Imron Date: Wed, 16 Feb 2022 13:27:56 +0100 Subject: [PATCH] refactor tests --- .../de/ci/exam/project/NotificationTest.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) 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 index fb77bb6..b1600f2 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/NotificationTest.java +++ b/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); } }