How do I specify a mediatype of text/plain;charset=UTF-8 in a Spring Boot Test

Issue

Here’s my test :

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

and it fails with this:

Expected :text/plain Actual :text/plain;charset=UTF-8

This is using the Kotlin DSL for MockMVC.

How do I change the accept to allow for charset=UTF-8 ?

Solution

There is one factory method which accepts custom value. Try:

MediaType.valueOf("text/plain;charset=UTF-8")

Answered By – Goro

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published