BAEL-88 Testing in Spring Boot (#1679)

Review comments
This commit is contained in:
Yasin 2017-04-18 23:12:29 +05:30 committed by maibin
parent dc561548b3
commit 553c368b5b
6 changed files with 14 additions and 13 deletions

View File

@ -5,9 +5,10 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@ -15,16 +16,16 @@ import org.springframework.web.bind.annotation.RestController;
public class EmployeeRestController {
@Autowired
EmployeeService employeeService;
private EmployeeService employeeService;
@RequestMapping(value = "/employees", method = RequestMethod.POST)
@PostMapping("/employees")
public ResponseEntity<Employee> createEmployee(@RequestBody Employee employee) {
HttpStatus status = HttpStatus.CREATED;
Employee saved = employeeService.save(employee);
return new ResponseEntity<>(saved, status);
}
@RequestMapping(value = "/employees", method = RequestMethod.GET)
@GetMapping("/employees")
public List<Employee> getAllEmployees() {
return employeeService.getAllEmployees();
}

View File

@ -13,7 +13,7 @@ import org.springframework.stereotype.Service;
public class EmployeeServiceImpl implements EmployeeService {
@Autowired
EmployeeRepository employeeRepository;
private EmployeeRepository employeeRepository;
@Override
public Optional<Employee> getEmployeeById(Long id) {

View File

@ -20,10 +20,10 @@ import org.springframework.test.context.junit4.SpringRunner;
public class EmployeeRepositoryTest {
@Autowired
TestEntityManager entityManager;
private TestEntityManager entityManager;
@Autowired
EmployeeRepository employeeRepository;
private EmployeeRepository employeeRepository;
@Test
public void whenFindByName_thenReturnEmployee() {

View File

@ -34,10 +34,10 @@ import org.springframework.test.web.servlet.MockMvc;
public class EmployeeRestControllerIntTest {
@Autowired
MockMvc mvc;
private MockMvc mvc;
@Autowired
EmployeeRepository repository;
private EmployeeRepository repository;
@After
public void resetDb() {

View File

@ -33,10 +33,10 @@ import org.springframework.test.web.servlet.MockMvc;
public class EmployeeRestControllerTest {
@Autowired
MockMvc mvc;
private MockMvc mvc;
@MockBean
EmployeeService service;
private EmployeeService service;
@Before
public void setUp() throws Exception {

View File

@ -34,10 +34,10 @@ public class EmployeeServiceImplTest {
}
@Autowired
EmployeeService employeeService;
private EmployeeService employeeService;
@MockBean
EmployeeRepository employeeRepository;
private EmployeeRepository employeeRepository;
@Before
public void setUp() {