diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/MimeTypesTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/MimeTypesTest.java new file mode 100644 index 00000000000..e3ea2973793 --- /dev/null +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/MimeTypesTest.java @@ -0,0 +1,50 @@ +package org.eclipse.jetty.http; + +import org.eclipse.jetty.io.Buffer; +import org.junit.Assert; +import org.junit.Test; + +public class MimeTypesTest +{ + @Test + public void testGetMimeByExtension_Gzip() + { + assertMimeTypeByExtension("application/gzip","test.gz"); + } + + @Test + public void testGetMimeByExtension_Png() + { + assertMimeTypeByExtension("image/png","test.png"); + assertMimeTypeByExtension("image/png","TEST.PNG"); + assertMimeTypeByExtension("image/png","Test.Png"); + } + + @Test + public void testGetMimeByExtension_Png_MultiDot() + { + assertMimeTypeByExtension("image/png","org.eclipse.jetty.Logo.png"); + } + + @Test + public void testGetMimeByExtension_Png_DeepPath() + { + assertMimeTypeByExtension("image/png","/org/eclipse/jetty/Logo.png"); + } + + @Test + public void testGetMimeByExtension_Text() + { + assertMimeTypeByExtension("text/plain","test.txt"); + assertMimeTypeByExtension("text/plain","TEST.TXT"); + } + + private void assertMimeTypeByExtension(String expectedMimeType, String filename) + { + MimeTypes mimetypes = new MimeTypes(); + Buffer contentType = mimetypes.getMimeByExtension(filename); + String prefix = "MimeTypes.getMimeByExtension(" + filename + ")"; + Assert.assertNotNull(prefix,contentType); + Assert.assertEquals(prefix,expectedMimeType,contentType.toString()); + } +}