@@ -22,7 +22,7 @@ import org.junit.Test
22
22
import org.junit.jupiter.api.assertThrows
23
23
import org.springframework.http.HttpMethod
24
24
import org.springframework.http.HttpStatus
25
- import org.springframework.http.MediaType
25
+ import org.springframework.http.MediaType.*
26
26
import org.springframework.test.web.Person
27
27
import org.springframework.test.web.servlet.setup.MockMvcBuilders
28
28
import org.springframework.web.bind.annotation.*
@@ -44,26 +44,26 @@ class MockMvcExtensionsTests {
44
44
fun request () {
45
45
mockMvc.request(HttpMethod .GET , " /person/{name}" , " Lee" ) {
46
46
secure = true
47
- accept = MediaType . APPLICATION_JSON
47
+ accept = APPLICATION_JSON
48
48
headers {
49
49
contentLanguage = Locale .FRANCE
50
50
}
51
51
principal = Principal { " foo" }
52
- } andExpect {
52
+ }. andExpect {
53
53
status { isOk }
54
- content { contentType(" application/json;charset=UTF-8 " ) }
54
+ content { contentType(APPLICATION_JSON_UTF8 ) }
55
55
jsonPath(" $.name" ) { value(" Lee" ) }
56
56
content { json(""" {"someBoolean": false}""" , false ) }
57
- } andDo {
57
+ }. andDo {
58
58
print ()
59
59
}
60
60
}
61
61
62
62
@Test
63
63
fun `request without MockHttpServletRequestDsl` () {
64
- mockMvc.request(HttpMethod .GET , " /person/{name}" , " Lee" ) andExpect {
64
+ mockMvc.request(HttpMethod .GET , " /person/{name}" , " Lee" ). andExpect {
65
65
status { isOk }
66
- } andDo {
66
+ }. andDo {
67
67
print ()
68
68
}
69
69
}
@@ -74,11 +74,11 @@ class MockMvcExtensionsTests {
74
74
var handlerInvoked = false
75
75
val matcher = ResultMatcher { matcherInvoked = true }
76
76
val handler = ResultHandler { handlerInvoked = true }
77
- mockMvc.request(HttpMethod .GET , " /person/{name}" , " Lee" ) andExpect {
77
+ mockMvc.request(HttpMethod .GET , " /person/{name}" , " Lee" ). andExpect {
78
78
status { isOk }
79
- } andExpect {
79
+ }. andExpect {
80
80
match(matcher)
81
- } andDo {
81
+ }. andDo {
82
82
handle(handler)
83
83
}
84
84
Assert .assertTrue(matcherInvoked)
@@ -89,17 +89,17 @@ class MockMvcExtensionsTests {
89
89
fun get () {
90
90
mockMvc.get(" /person/{name}" , " Lee" ) {
91
91
secure = true
92
- accept = MediaType . APPLICATION_JSON
92
+ accept = APPLICATION_JSON_UTF8
93
93
headers {
94
94
contentLanguage = Locale .FRANCE
95
95
}
96
96
principal = Principal { " foo" }
97
- } andExpect {
97
+ }. andExpect {
98
98
status { isOk }
99
- content { contentType(" application/json;charset=UTF-8 " ) }
99
+ content { contentType(APPLICATION_JSON_UTF8 ) }
100
100
jsonPath(" $.name" ) { value(" Lee" ) }
101
101
content { json(""" {"someBoolean": false}""" , false ) }
102
- } andDo {
102
+ }. andDo {
103
103
print ()
104
104
}
105
105
}
@@ -109,10 +109,10 @@ class MockMvcExtensionsTests {
109
109
mockMvc.post(" /person" ) {
110
110
content = """ { "name": "foo" }"""
111
111
headers {
112
- accept = listOf (MediaType . APPLICATION_JSON )
113
- contentType = MediaType . APPLICATION_JSON
112
+ accept = listOf (APPLICATION_JSON )
113
+ contentType = APPLICATION_JSON
114
114
}
115
- } andExpect {
115
+ }. andExpect {
116
116
status {
117
117
isCreated
118
118
}
@@ -123,9 +123,9 @@ class MockMvcExtensionsTests {
123
123
fun `negative assertion tests to verify the matchers throw errors when expected` () {
124
124
val name = " Petr"
125
125
mockMvc.get(" /person/$name " ) {
126
- accept = MediaType . APPLICATION_JSON
127
- } andExpect {
128
- assertThrows<AssertionError > { content { contentType(MediaType . APPLICATION_ATOM_XML ) } }
126
+ accept = APPLICATION_JSON
127
+ }. andExpect {
128
+ assertThrows<AssertionError > { content { contentType(APPLICATION_ATOM_XML ) } }
129
129
assertThrows<AssertionError > { content { string(" Wrong" ) } }
130
130
assertThrows<AssertionError > { jsonPath(" name" , CoreMatchers .`is `(" Wrong" )) }
131
131
assertThrows<AssertionError > { content { json(""" {"name":"wrong"}""" ) } }
@@ -146,11 +146,11 @@ class MockMvcExtensionsTests {
146
146
@Test
147
147
fun `negative assertion tests for xpath` () {
148
148
mockMvc.get(" /person/Clint" ) {
149
- accept = MediaType . APPLICATION_XML
150
- } andExpect {
149
+ accept = APPLICATION_XML
150
+ }. andExpect {
151
151
status { isOk }
152
152
assertThrows<AssertionError > { xpath(" //wrong" ) { nodeCount(1 ) } }
153
- } andDo {
153
+ }. andDo {
154
154
print ()
155
155
}
156
156
}
0 commit comments