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
package com.its.reservation; | |
import org.assertj.core.api.Assertions; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | |
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; | |
import org.springframework.test.context.junit4.SpringRunner; |
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
package com.its.reservation.repository; | |
import org.springframework.data.repository.CrudRepository; | |
public interface ReservationRepository extends CrudRepository<Reservation, Long> { | |
Reservation findByFirstName(String name); | |
} |
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
@Service | |
public class ReservationService { | |
private ReservationRepository reservationRepository; | |
public ReservationService(ReservationRepository reservationRepository) { | |
this.reservationRepository = reservationRepository; | |
} | |
public Reservation getReservationDetails(String name) { | |
System.out.println("Entering and leaving ReservationService : getReservationDetails " |
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); |
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); |
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
package com.its.reservation.service; | |
import org.springframework.stereotype.Service; | |
import com.its.reservation.repository.Reservation; | |
import com.its.reservation.repository.ReservationRepository; | |
@Service | |
public class ReservationService { | |
private ReservationRepository reservationRepository; |
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
package com.its.reservation; | |
import static org.assertj.core.api.Assertions.assertThat; | |
import org.junit.Test; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import com.its.reservation.repository.Reservation; | |
import com.its.reservation.service.ReservationService; |
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(SpringRunner.class) | |
@WebMvcTest(ReservationController.class) | |
public class ReservationControllerTest { | |
@Autowired | |
private MockMvc mockMvc; | |
@MockBean | |
ReservationService reservationService; | |
@Test |
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
@RestController | |
@RequestMapping("/reservation") | |
public class ReservationController { | |
private ReservationService reservationService; | |
public ReservationController(ReservationService reservationService) { | |
this.reservationService = reservationService; | |
} | |
@RequestMapping(method = RequestMethod.GET, value = "/{name}") |
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(SpringRunner.class) | |
@WebMvcTest(ReservationController.class) | |
public class ReservationControllerTest { | |
@Autowired | |
private MockMvc mockMvc; | |
@MockBean | |
ReservationService reservationService; | |
@Test |