Last active
March 11, 2018 05:42
-
-
Save dhaval201279/7ca44f18d033e19c2007ab8284fb9f2f to your computer and use it in GitHub Desktop.
1st version of ReservationCachingTest
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.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.ArgumentMatchers; | |
import org.mockito.BDDMockito; | |
import org.mockito.Mockito; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.boot.test.mock.mockito.MockBean; | |
import org.springframework.test.context.junit4.SpringRunner; | |
import com.its.reservation.repository.Reservation; | |
import com.its.reservation.repository.ReservationRepository; | |
import com.its.reservation.service.ReservationService; | |
/** | |
* @author Dhaval | |
* | |
*/ | |
@RunWith(SpringRunner.class) | |
@SpringBootTest(webEnvironment=SpringBootTest.WebEnvironment.NONE) | |
@AutoConfigureTestDatabase | |
public class ReservationCachingTest { | |
@Autowired | |
ReservationService reservationService; | |
@MockBean | |
ReservationRepository reservationRepository; | |
@Test | |
public void caching_reducesDBCall() { | |
BDDMockito.given(reservationRepository.findByFirstName(ArgumentMatchers.anyString())) | |
.willReturn(new Reservation(Long.valueOf(1),"Dhaval","Shah")); | |
reservationService.getReservationDetails("Dhaval"); | |
reservationService.getReservationDetails("Dhaval"); | |
Mockito.verify(reservationRepository, Mockito.times(1)).findByFirstName("Dhaval"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment