|
21 | 21 | import org.junit.jupiter.params.provider.MethodSource;
|
22 | 22 |
|
23 | 23 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 24 | +import static org.hamcrest.Matchers.greaterThan; |
24 | 25 | import static org.hamcrest.Matchers.is;
|
| 26 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
25 | 27 | import static org.junit.jupiter.api.Assertions.assertNull;
|
26 | 28 |
|
27 | 29 | public class MimeTypesTest
|
@@ -148,4 +150,38 @@ public void testMimeTypesGetBaseType(String contentTypeWithCharset, MimeTypes.Ty
|
148 | 150 | {
|
149 | 151 | assertThat(MimeTypes.getBaseType(contentTypeWithCharset), is(expectedType));
|
150 | 152 | }
|
| 153 | + |
| 154 | + /** |
| 155 | + * Test of a use case where the webapp wants a specific set of mime types, |
| 156 | + * no defaults. This is accomplished by replacing getting the MimeTypes.Mutable |
| 157 | + * associated with the webapp, calling clear, and then setting the values you want. |
| 158 | + */ |
| 159 | + @Test |
| 160 | + public void testMimeTypesMutableClear() |
| 161 | + { |
| 162 | + MimeTypes.Mutable webappMimeTypes = new MimeTypes.Mutable(); |
| 163 | + |
| 164 | + // Verify that "defaults" behavior is still there. |
| 165 | + assertEquals("UTF-8", webappMimeTypes.getAssumedCharsetName("application/json")); |
| 166 | + assertThat(webappMimeTypes._mimeMap.size(), greaterThan(100)); |
| 167 | + |
| 168 | + // Clear out the mime-types |
| 169 | + webappMimeTypes.clear(); |
| 170 | + assertThat(webappMimeTypes._mimeMap.size(), is(0)); |
| 171 | + assertThat(webappMimeTypes._assumedEncodings.size(), is(0)); |
| 172 | + assertThat(webappMimeTypes._assumedNoEncodings.size(), is(0)); |
| 173 | + assertThat(webappMimeTypes._inferredEncodings.size(), is(0)); |
| 174 | + |
| 175 | + // Set a few new values |
| 176 | + webappMimeTypes.addMimeMapping("html", "text/html"); |
| 177 | + // HTML is inferred to be UTF-8, and will always have a 'charset' on the content-type header |
| 178 | + webappMimeTypes.addInferred("text/html", "utf-8"); |
| 179 | + |
| 180 | + webappMimeTypes.addMimeMapping("json", "application/json"); |
| 181 | + // JSON is always UTF-8, and is never represented as a 'charset' on the content-type header |
| 182 | + webappMimeTypes.addAssumed("application/json", "utf-8"); |
| 183 | + |
| 184 | + // Images never have a 'charset' on the content-type field |
| 185 | + webappMimeTypes.addAssumed("image/*", null); |
| 186 | + } |
151 | 187 | }
|
0 commit comments