From 2f2fe9bd05fa1b91ac44e9b80d22fcbfd1c9270a Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 26 Aug 2014 23:54:02 +0200 Subject: [PATCH] Verify custom MIME type support in MockServletContext --- .../mock/web/MockServletContextTests.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java index da6d0bc14c..30f5b80d83 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -17,10 +17,15 @@ package org.springframework.mock.web; import java.util.Set; + +import javax.activation.FileTypeMap; +import javax.activation.MimetypesFileTypeMap; import javax.servlet.RequestDispatcher; import org.junit.Test; +import static org.hamcrest.CoreMatchers.*; + import static org.junit.Assert.*; /** @@ -75,6 +80,19 @@ public class MockServletContextTests { assertEquals("image/gif", sc.getMimeType("test.gif")); } + /** + * Introduced to dispel claims in a thread on Stack Overflow: + * Testing Spring managed servlet + */ + @Test + public void getMimeTypeWithCustomConfiguredType() { + FileTypeMap defaultFileTypeMap = MimetypesFileTypeMap.getDefaultFileTypeMap(); + assertThat(defaultFileTypeMap, instanceOf(MimetypesFileTypeMap.class)); + MimetypesFileTypeMap mimetypesFileTypeMap = (MimetypesFileTypeMap) defaultFileTypeMap; + mimetypesFileTypeMap.addMimeTypes("text/enigma enigma"); + assertEquals("text/enigma", sc.getMimeType("filename.enigma")); + } + @Test public void servletVersion() { assertEquals(3, sc.getMajorVersion());