Updated methods
This commit is contained in:
parent
40013de660
commit
0844dcd3b7
@ -20,7 +20,6 @@ public class EmployeeController {
|
|||||||
|
|
||||||
@PostMapping("/employee")
|
@PostMapping("/employee")
|
||||||
public Employee createUser(@RequestBody Employee employee) {
|
public Employee createUser(@RequestBody Employee employee) {
|
||||||
System.out.println(employee);
|
|
||||||
empRepository.save(employee);
|
empRepository.save(employee);
|
||||||
return employee;
|
return employee;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class EmployeeControllerUnitTest {
|
|||||||
Mockito.when(employeeRepository.findById(1234)).thenReturn(Optional.of(employeeExpected));
|
Mockito.when(employeeRepository.findById(1234)).thenReturn(Optional.of(employeeExpected));
|
||||||
|
|
||||||
MvcResult result = mockMvc.perform(get("/employee/1234"))
|
MvcResult result = mockMvc.perform(get("/employee/1234"))
|
||||||
.andExpect(status().isOk()).andReturn();
|
.andExpect(status().isOk()).andReturn();
|
||||||
|
|
||||||
Employee employee = objectMapper.readValue(result.getResponse().getContentAsString(), Employee.class);
|
Employee employee = objectMapper.readValue(result.getResponse().getContentAsString(), Employee.class);
|
||||||
assertEquals(employeeExpected.getEmpName(), employee.getEmpName());
|
assertEquals(employeeExpected.getEmpName(), employee.getEmpName());
|
||||||
@ -61,8 +61,8 @@ public class EmployeeControllerUnitTest {
|
|||||||
Mockito.when(employeeRepository.save(employeeExpected)).thenReturn(employeeExpected);
|
Mockito.when(employeeRepository.save(employeeExpected)).thenReturn(employeeExpected);
|
||||||
|
|
||||||
MvcResult result = mockMvc.perform(post("/employee")
|
MvcResult result = mockMvc.perform(post("/employee")
|
||||||
.content(objectMapper.writeValueAsString(employeeExpected))
|
.content(objectMapper.writeValueAsString(employeeExpected))
|
||||||
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
|
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
|
||||||
|
|
||||||
Employee employee = objectMapper.readValue(result.getResponse().getContentAsString(), Employee.class);
|
Employee employee = objectMapper.readValue(result.getResponse().getContentAsString(), Employee.class);
|
||||||
assertEquals(employeeExpected.getEmpName(), employee.getEmpName());
|
assertEquals(employeeExpected.getEmpName(), employee.getEmpName());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user