Remove infix qualifier from ResultActionsDsl methods

The infix form limits the extensibility of the API and
prevents calling `andReturn()`.

See gh-1951
This commit is contained in:
Sebastien Deleuze
2019-03-04 19:15:12 +01:00
parent 0c332286f1
commit 9e873af6ab
3 changed files with 29 additions and 29 deletions

View File

@@ -12,7 +12,7 @@ class ResultActionsDsl(private val actions: ResultActions) {
* Provide access to [MockMvcResultMatchersDsl] Kotlin DSL.
* @see MockMvcResultMatchersDsl.match
*/
infix fun andExpect(dsl: MockMvcResultMatchersDsl.() -> Unit): ResultActionsDsl {
fun andExpect(dsl: MockMvcResultMatchersDsl.() -> Unit): ResultActionsDsl {
MockMvcResultMatchersDsl(actions).dsl()
return this
}
@@ -21,7 +21,7 @@ class ResultActionsDsl(private val actions: ResultActions) {
* Provide access to [MockMvcResultHandlersDsl] Kotlin DSL.
* @see MockMvcResultHandlersDsl.handle
*/
infix fun andDo(dsl: MockMvcResultHandlersDsl.() -> Unit): ResultActionsDsl {
fun andDo(dsl: MockMvcResultHandlersDsl.() -> Unit): ResultActionsDsl {
MockMvcResultHandlersDsl(actions).dsl()
return this
}

View File

@@ -22,7 +22,7 @@ import org.junit.Test
import org.junit.jupiter.api.assertThrows
import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.MediaType.*
import org.springframework.test.web.Person
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.springframework.web.bind.annotation.*
@@ -44,26 +44,26 @@ class MockMvcExtensionsTests {
fun request() {
mockMvc.request(HttpMethod.GET, "/person/{name}", "Lee") {
secure = true
accept = MediaType.APPLICATION_JSON
accept = APPLICATION_JSON
headers {
contentLanguage = Locale.FRANCE
}
principal = Principal { "foo" }
} andExpect {
}.andExpect {
status { isOk }
content { contentType("application/json;charset=UTF-8") }
content { contentType(APPLICATION_JSON_UTF8) }
jsonPath("$.name") { value("Lee") }
content { json("""{"someBoolean": false}""", false) }
} andDo {
}.andDo {
print()
}
}
@Test
fun `request without MockHttpServletRequestDsl`() {
mockMvc.request(HttpMethod.GET, "/person/{name}", "Lee") andExpect {
mockMvc.request(HttpMethod.GET, "/person/{name}", "Lee").andExpect {
status { isOk }
} andDo {
}.andDo {
print()
}
}
@@ -74,11 +74,11 @@ class MockMvcExtensionsTests {
var handlerInvoked = false
val matcher = ResultMatcher { matcherInvoked = true }
val handler = ResultHandler { handlerInvoked = true }
mockMvc.request(HttpMethod.GET, "/person/{name}", "Lee") andExpect {
mockMvc.request(HttpMethod.GET, "/person/{name}", "Lee").andExpect {
status { isOk }
} andExpect {
}.andExpect {
match(matcher)
} andDo {
}.andDo {
handle(handler)
}
Assert.assertTrue(matcherInvoked)
@@ -89,17 +89,17 @@ class MockMvcExtensionsTests {
fun get() {
mockMvc.get("/person/{name}", "Lee") {
secure = true
accept = MediaType.APPLICATION_JSON
accept = APPLICATION_JSON_UTF8
headers {
contentLanguage = Locale.FRANCE
}
principal = Principal { "foo" }
} andExpect {
}.andExpect {
status { isOk }
content { contentType("application/json;charset=UTF-8") }
content { contentType(APPLICATION_JSON_UTF8) }
jsonPath("$.name") { value("Lee") }
content { json("""{"someBoolean": false}""", false) }
} andDo {
}.andDo {
print()
}
}
@@ -109,10 +109,10 @@ class MockMvcExtensionsTests {
mockMvc.post("/person") {
content = """{ "name": "foo" }"""
headers {
accept = listOf(MediaType.APPLICATION_JSON)
contentType = MediaType.APPLICATION_JSON
accept = listOf(APPLICATION_JSON)
contentType = APPLICATION_JSON
}
} andExpect {
}.andExpect {
status {
isCreated
}
@@ -123,9 +123,9 @@ class MockMvcExtensionsTests {
fun `negative assertion tests to verify the matchers throw errors when expected`() {
val name = "Petr"
mockMvc.get("/person/$name") {
accept = MediaType.APPLICATION_JSON
} andExpect {
assertThrows<AssertionError> { content { contentType(MediaType.APPLICATION_ATOM_XML) } }
accept = APPLICATION_JSON
}.andExpect {
assertThrows<AssertionError> { content { contentType(APPLICATION_ATOM_XML) } }
assertThrows<AssertionError> { content { string("Wrong") } }
assertThrows<AssertionError> { jsonPath("name", CoreMatchers.`is`("Wrong")) }
assertThrows<AssertionError> { content { json("""{"name":"wrong"}""") } }
@@ -146,11 +146,11 @@ class MockMvcExtensionsTests {
@Test
fun `negative assertion tests for xpath`() {
mockMvc.get("/person/Clint") {
accept = MediaType.APPLICATION_XML
} andExpect {
accept = APPLICATION_XML
}.andExpect {
status { isOk }
assertThrows<AssertionError> { xpath("//wrong") { nodeCount(1) } }
} andDo {
}.andDo {
print()
}
}

View File

@@ -336,17 +336,17 @@ better discoverability (no usage of static methods).
val mockMvc: MockMvc = ...
mockMvc.get("/person/{name}", "Lee") {
secure = true
accept = MediaType.APPLICATION_JSON
accept = APPLICATION_JSON
headers {
contentLanguage = Locale.FRANCE
}
principal = Principal { "foo" }
} andExpect {
}.andExpect {
status { isOk }
content { contentType("application/json;charset=UTF-8") }
content { contentType(APPLICATION_JSON_UTF8) }
jsonPath("$.name") { value("Lee") }
content { json("""{"someBoolean": false}""", false) }
} andDo {
}.andDo {
print()
}
----