Skip to content

Instantly share code, notes, and snippets.

View gohilronak's full-sized avatar

Ronak gohilronak

View GitHub Profile
@gohilronak
gohilronak / tdd-spring-CarControllerTest.java
Last active December 14, 2018 12:26
Test Driven Development with Spring Boot CarControllerTest.java file
package com.example.tdd.controller;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.junit.runner.RunWith;
@gohilronak
gohilronak / tdd-spring-v1-CarControllerTest.java
Created December 14, 2018 12:51
Unit Test REST endpoint with MockMvc and check if status is 200 OK
package com.example.tdd.controller;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
@gohilronak
gohilronak / tdd-spring-v1-CarController.java
Created December 14, 2018 12:58
Test Driven Development with Spring Boot CarController.java file
package com.example.tdd.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CarController {
@GetMapping("cars/{name}")