@@ -4,13 +4,15 @@ import com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document
4
4
import com.epages.restdocs.apispec.ResourceDocumentation
5
5
import com.epages.restdocs.apispec.ResourceSnippetParameters
6
6
import com.epages.restdocs.apispec.SimpleType
7
+ import com.j.docs.common.createRequest
7
8
import com.j.docs.common.response.CommonResponse
8
- import com.j.docs.student.common.createRequest
9
- import com.j.docs.student.common.toObject
9
+ import com.j.docs.common.toObject
10
10
import com.j.docs.student.controller.request.StudentCreationRequest
11
11
import com.j.docs.student.service.StudentCreationService
12
12
import com.j.docs.student.service.StudentSearchService
13
+ import org.assertj.core.api.Assertions.assertThat
13
14
import org.junit.jupiter.api.Test
15
+ import org.mockito.BDDMockito.*
14
16
import org.springframework.beans.factory.annotation.Autowired
15
17
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
16
18
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
@@ -20,7 +22,7 @@ import org.springframework.http.HttpMethod
20
22
import org.springframework.restdocs.payload.JsonFieldType
21
23
import org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath
22
24
import org.springframework.test.web.servlet.MockMvc
23
- import org.springframework.test.web.servlet.result.MockMvcResultMatchers
25
+ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
24
26
25
27
@WebMvcTest(StudentController ::class )
26
28
@AutoConfigureRestDocs
@@ -38,23 +40,33 @@ internal class StudentControllerTest {
38
40
39
41
@Test
40
42
fun `학생 등록하기 - CREATED` () {
43
+ willDoNothing().given(
44
+ studentCreationService.create(
45
+ studentFirstName = " 진혁" ,
46
+ studentLastName = " 이" ,
47
+ studentGrade = 3 ,
48
+ studentClassroom = 4 ,
49
+ studentNumber = 17 ,
50
+ )
51
+ )
52
+
41
53
val requestBody = StudentCreationRequest (
42
54
student = StudentCreationRequest .StudentInfo (
43
- firstName = " 이 " ,
44
- lastName = " 진혁 " ,
55
+ firstName = " 진혁 " ,
56
+ lastName = " 이 " ,
45
57
grade = 3 ,
46
58
classroom = 4 ,
47
59
number = 17 ,
48
60
)
49
61
)
50
62
51
- val response = mockMvc.perform(
63
+ val result = mockMvc.perform(
52
64
createRequest(
53
65
httpMethod = HttpMethod .POST ,
54
66
url = " /students" ,
55
67
requestBody = requestBody,
56
68
))
57
- .andExpect(MockMvcResultMatchers . status().isCreated)
69
+ .andExpect(status().isCreated)
58
70
.andDo(
59
71
document(
60
72
" 학생 등록하기 - CREATED" ,
@@ -96,5 +108,25 @@ internal class StudentControllerTest {
96
108
.response
97
109
.contentAsString
98
110
.toObject<CommonResponse <Nothing >>()
111
+
112
+ // verify(studentCreationService).create(
113
+ // studentFirstName = "진혁",
114
+ // studentLastName = "이",
115
+ // studentGrade = 3,
116
+ // studentClassroom = 4,
117
+ // studentNumber = 17,
118
+ // )
119
+ then(studentCreationService)
120
+ .should()
121
+ .create(
122
+ studentFirstName = " 진혁" ,
123
+ studentLastName = " 이" ,
124
+ studentGrade = 3 ,
125
+ studentClassroom = 4 ,
126
+ studentNumber = 17 ,
127
+ )
128
+
129
+ assertThat(result.errorCode).isNull()
130
+ assertThat(result.errorMessage).isNull()
99
131
}
100
132
}
0 commit comments