Add contentTypeCompatibleWith option to Spring MVC Test

An expectation such as content().contentType(MediaType.TEXT_PLAIN)
fails if the actual media type contains a charset or another parameter.
A new method allows comparing the media type and subtype only via
content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN).

Issue: SPR-10165
This commit is contained in:
Rossen Stoyanchev
2013-01-14 21:38:51 -05:00
parent 9dc7b5feef
commit b2d6596901
3 changed files with 60 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,7 +62,9 @@ public class ContentAssertionTests {
this.mockMvc.perform(get("/handleUtf8"))
.andExpect(content().contentType(MediaType.valueOf("text/plain;charset=UTF-8")))
.andExpect(content().contentType("text/plain;charset=UTF-8"));
.andExpect(content().contentType("text/plain;charset=UTF-8"))
.andExpect(content().contentTypeCompatibleWith("text/plan"))
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN));
}
@Test