如何在 Spring Boot 测试中指定 text/plain;charset=UTF-8 的媒体类型

Pau*_*NUK 5 spring spring-mvc kotlin spring-boot mockmvc

这是我的测试:

 @Test
 fun `test config properties`() {
    mockMvc.request(HttpMethod.GET,"someUrl") {
        accept = MediaType.TEXT_PLAIN
    }.andExpect {
        status { isOk }
        content { contentType(MediaType.TEXT_PLAIN) }
    }
}
Run Code Online (Sandbox Code Playgroud)

它失败了:

预期:text/plain 实际:text/plain;charset=UTF-8

这是使用适用于 MockMVC 的 Kotlin DSL。

如何更改接受以允许 charset=UTF-8 ?

Gor*_*oro 9

有一种工厂方法接受自定义值。尝试:

MediaType.valueOf("text/plain;charset=UTF-8")
Run Code Online (Sandbox Code Playgroud)