Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Dhaval Shah dhaval201279

🎯
Focusing
View GitHub Profile
@dhaval201279
dhaval201279 / ReservationRepositoryTest1.java
Last active Mar 11, 2018
1st version of ReservationRepositoryTest - that passes when tested with CUT
View ReservationRepositoryTest1.java
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 / ReservationRepository1.java
Last active Mar 11, 2018
1st version of ReservationRepository - for removing compilation error whilst executing test of ReservationService
View ReservationRepository1.java
package com.its.reservation.repository;
import org.springframework.data.repository.CrudRepository;
public interface ReservationRepository extends CrudRepository<Reservation, Long> {
Reservation findByFirstName(String name);
}
@dhaval201279
dhaval201279 / ReservationService3.java
Last active Mar 11, 2018
3rd version of ReservationService - with null check and addition of ReservationNotFoundException
View ReservationService3.java
@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 / ReservationServiceTest3.java
Last active Mar 11, 2018
3rd version of ReservationServiceTest - with ReservationRepository returning null
View ReservationServiceTest3.java
@RunWith(MockitoJUnitRunner.class)
public class ReservationServiceTest {
ReservationService reservationService;
@Mock
ReservationRepository reservationRepository;
@Before
public void setUp() throws Exception {
reservationService = new ReservationService(reservationRepository);
@dhaval201279
dhaval201279 / ReservationServiceTest2.java
Last active Mar 11, 2018
2nd version ReservationServiceTest - with mock collaborators and passed test case
View ReservationServiceTest2.java
@RunWith(MockitoJUnitRunner.class)
public class ReservationServiceTest {
ReservationService reservationService;
@Mock
ReservationRepository reservationRepository;
@Before
public void setUp() throws Exception {
reservationService = new ReservationService(reservationRepository);
@dhaval201279
dhaval201279 / ReservationService2.java
Last active Mar 11, 2018
2nd version of ReservationService - with required collaborator i.e ReservationRepository
View ReservationService2.java
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 / ReservationServiceTest1.java
Last active Mar 11, 2018
1st version of ReservationServiceTest - which fails initially
View ReservationServiceTest1.java
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;
@dhaval201279
dhaval201279 / ReservationControllerTest3.java
Last active Mar 11, 2018
3rd version of ReservationControllerTest
View ReservationControllerTest3.java
@RunWith(SpringRunner.class)
@WebMvcTest(ReservationController.class)
public class ReservationControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
ReservationService reservationService;
@Test
@dhaval201279
dhaval201279 / ReservationController3.java
Last active Mar 11, 2018
3rd version of ReservationController with Exception Handler
View ReservationController3.java
@RestController
@RequestMapping("/reservation")
public class ReservationController {
private ReservationService reservationService;
public ReservationController(ReservationService reservationService) {
this.reservationService = reservationService;
}
@RequestMapping(method = RequestMethod.GET, value = "/{name}")
@dhaval201279
dhaval201279 / ReservationControllerTest2.java
Last active Mar 11, 2018
2nd Version of ReservationControllerTest
View ReservationControllerTest2.java
@RunWith(SpringRunner.class)
@WebMvcTest(ReservationController.class)
public class ReservationControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
ReservationService reservationService;
@Test
You can’t perform that action at this time.