Updated methods

This commit is contained in:
Saikat Chakraborty 2022-09-22 09:55:21 +05:30
parent 40013de660
commit 0844dcd3b7
2 changed files with 3 additions and 4 deletions

View File

@ -20,7 +20,6 @@ public class EmployeeController {
@PostMapping("/employee")
public Employee createUser(@RequestBody Employee employee) {
System.out.println(employee);
empRepository.save(employee);
return employee;
}

View File

@ -43,7 +43,7 @@ public class EmployeeControllerUnitTest {
Mockito.when(employeeRepository.findById(1234)).thenReturn(Optional.of(employeeExpected));
MvcResult result = mockMvc.perform(get("/employee/1234"))
.andExpect(status().isOk()).andReturn();
.andExpect(status().isOk()).andReturn();
Employee employee = objectMapper.readValue(result.getResponse().getContentAsString(), Employee.class);
assertEquals(employeeExpected.getEmpName(), employee.getEmpName());
@ -61,8 +61,8 @@ public class EmployeeControllerUnitTest {
Mockito.when(employeeRepository.save(employeeExpected)).thenReturn(employeeExpected);
MvcResult result = mockMvc.perform(post("/employee")
.content(objectMapper.writeValueAsString(employeeExpected))
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
.content(objectMapper.writeValueAsString(employeeExpected))
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
Employee employee = objectMapper.readValue(result.getResponse().getContentAsString(), Employee.class);
assertEquals(employeeExpected.getEmpName(), employee.getEmpName());