### Question:
FileUploadServlet extends HttpServlet { protected String getFilenameLastSegment(final String fileName) { int slashPos = fileName.lastIndexOf("/"); if (slashPos == -1) { slashPos = fileName.lastIndexOf("\\"); } return fileName.substring(slashPos+1); }  @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 getFilenameLastSegment_should_return_proper_filename() { final String filename = "C:\\Users\\Desktop\\process.bar"; final String filenameLastSegment = fileUploadServlet.getFilenameLastSegment(filename); assertThat(filenameLastSegment).isEqualTo("process.bar"); }
@Test public void getFilenameLastSegment_should_return_proper_filename_for_linux_paths() { final String filename = "/Users/Deskt.op/process.bar"; final String filenameLastSegment = fileUploadServlet.getFilenameLastSegment(filename); assertThat(filenameLastSegment).isEqualTo("process.bar"); }
@Test public void getFilenameLastSegment_should_return_an_empty_filename_for_parent_folder_filename() throws IOException { final String filename = "../../../"; final String filenameLastSegment = fileUploadServlet.getFilenameLastSegment(filename); assertThat(filenameLastSegment).isEqualTo(""); }