Skip to content

Instantly share code, notes, and snippets.

@dhaval201279
Last active March 11, 2018 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaval201279/90d90ca18c1ba6904d759f110f657894 to your computer and use it in GitHub Desktop.
Save dhaval201279/90d90ca18c1ba6904d759f110f657894 to your computer and use it in GitHub Desktop.
3rd version of ReservationServiceTest - with ReservationRepository returning null
@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