Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Dhaval Shah dhaval201279

🎯
Focusing
Block or report user

Report or block dhaval201279

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dhaval201279
dhaval201279 / ReservationService4.java
Created Mar 11, 2018
4th version ReservationService - with @Cacheable
View ReservationService4.java
@Service
public class ReservationService {
private ReservationRepository reservationRepository;
public ReservationService(ReservationRepository reservationRepository) {
this.reservationRepository = reservationRepository;
}
@Cacheable("reservation")
@dhaval201279
dhaval201279 / BootifulTddApplication1.java
Created Mar 11, 2018
BootifulTddApplication - with caching annotation
View BootifulTddApplication1.java
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 / ReservationEndToEndTest2.java
Last active Mar 11, 2018
final version of ReservationEndToEndTest
View ReservationEndToEndTest2.java
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ReservationEndToEndTest {
@Autowired
TestRestTemplate testRestTemplate;
@Test
public void getReservation_shouldReturnReservationDetails() {
// Arrange
@dhaval201279
dhaval201279 / ReservationCachingTest1.java
Last active Mar 11, 2018
1st version of ReservationCachingTest
View ReservationCachingTest1.java
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 / 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 / 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 / ReservationService1.java
Last active Mar 11, 2018
1st version of ReservationService - with null as return type
View ReservationService1.java
package com.its.reservation.service;
import org.springframework.stereotype.Service;
import com.its.reservation.repository.Reservation;
@Service
public class ReservationService {
public Reservation getReservationDetails(String name) {
return null;
You can’t perform that action at this time.