### Question:
FileUploadServlet extends HttpServlet { protected String getExtension(final String fileName) { String extension = ""; final String filenameLastSegment = getFilenameLastSegment(fileName); final int dotPos = filenameLastSegment.lastIndexOf('.'); if (dotPos > -1) { extension = filenameLastSegment.substring(dotPos); } return extension; }  @Override void init(); @Override @SuppressWarnings("unchecked") void doPost(final HttpServletRequest request, final HttpServletResponse response); static final String RESPONSE_SEPARATOR; static final int MEGABYTE; }### Answer:
@Test public void getExtension_should_return_proper_extension() throws IOException { final String filename = "C:\\Users\\Desktop\\process.bar"; final String extension = fileUploadServlet.getExtension(filename); assertThat(extension).isEqualTo(".bar"); }
@Test public void getExtension_should_return_an_empty_extension() throws IOException { final String filename = "C:\\Users\\Desktop\\process"; final String extension = fileUploadServlet.getExtension(filename); assertThat(extension).isEqualTo(""); }
@Test public void getExtension_should_return_a_proper_extension_without_taking_care_of_dots() throws IOException { final String filename = "C:\\Users\\Deskt.op\\proc.ess.bar"; final String extension = fileUploadServlet.getExtension(filename); assertThat(extension).isEqualTo(".bar"); }
@Test public void getExtension_should_return_proper_extension_for_short_filename() throws IOException { final String filename = "process.bar"; final String extension = fileUploadServlet.getExtension(filename); assertThat(extension).isEqualTo(".bar"); }
@Test public void getExtension_should_return_proper_extension_for_linux_like_paths() throws IOException { final String filename = "/Users/Deskt.op/proc.ess.bar"; final String extension = fileUploadServlet.getExtension(filename); assertThat(extension).isEqualTo(".bar"); }
@Test public void getExtension_should_return_an_empty_extension_for_parent_folder_filename() throws IOException { final String filename = "../../../"; final String extension = fileUploadServlet.getExtension(filename); assertThat(extension).isEqualTo(""); }