Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
2nd version ReservationServiceTest - with mock collaborators and passed test case
@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");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment