@WebMvcTest(UserController.class) class UserControllerTest {
@Autowired private MockMvc mockMvc;
@MockBean private UserService userService;
@Test @DisplayName("사용자를 생성한다.") public void create() throws Exception { String email = "tester@example.com"; String name = "Tester"; String password = "test";
User mockUser = User.builder() .Id(1004L) .email(email) .password(password) .name(name) .build();
given(userService.registerUser(email, name, password)) .willReturn(mockUser);
ResultActions resultActions = mockMvc.perform(post("/users") .contentType(MediaType.APPLICATION_JSON) .content("{\"email\" : \"tester@example.com\", \"name\" : \"Tester\", \"password\" : \"test\"}"));
resultActions .andExpect(status().isCreated()) .andExpect(header().string("location", "/users/1004"));
verify(userService).registerUser(any(), any(), any()); } }
|