Last active
March 11, 2018 03:01
-
-
Save dhaval201279/90d90ca18c1ba6904d759f110f657894 to your computer and use it in GitHub Desktop.
3rd version of ReservationServiceTest - with ReservationRepository returning null
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(MockitoJUnitRunner.class) | |
public class ReservationServiceTest { | |
ReservationService reservationService; | |
@Mock | |
ReservationRepository reservationRepository; | |
@Before | |
public void setUp() throws Exception { | |
reservationService = new ReservationService(reservationRepository); | |
} | |
@Test | |
public void getReservationDetails_returnsReservationInfo() { | |
BDDMockito.given(reservationRepository.findByFirstName("Dhaval")) | |
.willReturn(new Reservation(Long.valueOf(1), "Dhaval", "Shah")); | |
Reservation aReservation = reservationService.getReservationDetails("Dhaval"); | |
assertThat(aReservation.getFirstName()).isEqualTo("Dhaval"); | |
assertThat(aReservation.getLastName()).isEqualTo("Shah"); | |
} | |
@Test(expected = ReservationNotFoundException.class) | |
public void getReservationDetails_whenNotFound() { | |
BDDMockito.given(reservationRepository.findByFirstName("Dhaval")).willReturn(null); | |
Reservation aReservation = reservationService.getReservationDetails("Dhaval"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment