MimeTypeTool { public String guessMimeTypeFromName(String r) { if(endsWith(r, ".html", ".htm")){ return "text/html"; } if(endsWith(r, ".js")){ return "text/javascript"; } if(endsWith(r, ".css")){ return "text/css"; } if(endsWith(r, ".png")){ return "image/png"; } if(endsWith(r, ".jpg", ".jpeg")){ return "image/jpeg"; } if(endsWith(r, ".gif")){ return "image/gif"; } return ""; }  String guessMimeTypeFromName(String r);  }
@Test public void detectsCommonFilenames(){ final Mapping[] mappings = { map("text/html", ".html", ".htm"), map("text/javascript", ".js"), map("text/css", ".css"), map("image/png", ".png"), map("image/jpeg", ".jpg", ".jpeg"), map("image/gif", ".gif") }; MimeTypeTool tool = new MimeTypeTool(); for(Mapping mapping : mappings){ for(String extension:mapping.extensions){ String result = tool.guessMimeTypeFromName("xyz123" + extension); Assert.assertEquals(mapping.mimeType, result); } } }