Skip to content

Instantly share code, notes, and snippets.

View dhaval201279's full-sized avatar
🎯
Focusing

Dhaval Shah dhaval201279

🎯
Focusing
View GitHub Profile
@dhaval201279
dhaval201279 / ReservationService2.java
Last active March 11, 2018 02:58
2nd version of ReservationService - with required collaborator i.e ReservationRepository
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;
@dhaval201279
dhaval201279 / ReservationServiceTest2.java
Last active March 11, 2018 03:00
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);
@dhaval201279
dhaval201279 / ReservationServiceTest3.java
Last active March 11, 2018 03:01
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);
@dhaval201279
dhaval201279 / ReservationService3.java
Last active March 11, 2018 03:02
3rd version of ReservationService - with null check and addition of ReservationNotFoundException
@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 "
@dhaval201279
dhaval201279 / ReservationRepositoryTest1.java
Last active March 11, 2018 05:23
1st version of ReservationRepositoryTest - that passes when tested with CUT
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;
@dhaval201279
dhaval201279 / ReservationCachingTest1.java
Last active March 11, 2018 05:42
1st version of ReservationCachingTest
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;
@dhaval201279
dhaval201279 / ReservationEndToEndTest2.java
Last active March 11, 2018 05:33
final version of ReservationEndToEndTest
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ReservationEndToEndTest {
@Autowired
TestRestTemplate testRestTemplate;
@Test
public void getReservation_shouldReturnReservationDetails() {
// Arrange
@dhaval201279
dhaval201279 / BootifulTddApplication1.java
Created March 11, 2018 05:37
BootifulTddApplication - with caching annotation
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching
public class BootifulTddApplication {
public static void main(String[] args) {
SpringApplication.run(BootifulTddApplication.class, args);
@dhaval201279
dhaval201279 / ReservationService4.java
Created March 11, 2018 05:40
4th version ReservationService - with @Cacheable
@Service
public class ReservationService {
private ReservationRepository reservationRepository;
public ReservationService(ReservationRepository reservationRepository) {
this.reservationRepository = reservationRepository;
}
@Cacheable("reservation")
@dhaval201279
dhaval201279 / HttpClientConfig1.java
Last active May 18, 2020 14:57
Configuring HttpClient using RequestConfig
private RequestConfig prepareHttpClientRequestConfig() {
RequestConfig requestConfig = RequestConfig
.custom()
.setConnectTimeout(CONNECT_TIMEOUT)
.setConnectionRequestTimeout(CONNECTION_REQUEST_TIMEOUT)
.setSocketTimeout(SOCKET_TIMEOUT)
.build();
return requestConfig;
}