PluginMediaServlet extends BaseUploadServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { try { final String filename = req.getRequestURI().substring(req.getContextPath().length()); final String pluginName = filename.replace(pattern, "/"); if (pluginName != null) { final FileItem fileItem = getFileItem(req); final String fileName = FilenameUtils.getName(fileItem.getName()); final Path path = resolve(pluginName + "/media/" + fileName); if (ioService.exists(path)) { writeResponse(response, "FAIL - ALREADY EXISTS"); return; } try { ioService.startBatch(path.getFileSystem()); writeFile(ioService, path, fileItem); } finally { ioService.endBatch(); } newMediaEvent.fire(new MediaAdded(pluginName.substring(1), new Media(pattern.substring(1) + pluginName.substring(1) + "/media/" + path.getFileName(), Paths.convert(path)))); writeResponse(response, "OK"); } } catch (final Exception e) { logError(e); writeResponse(response, "FAIL"); } }  @Override void init(final ServletConfig config); @Override void doGet(final HttpServletRequest req,
                      final HttpServletResponse resp);  }
@Test public void testDoPost() throws Exception { final FileItem fileItem = fileMock("C:\\Users\\user\\Desktop\\image.jpg"); final PluginMediaServlet servlet = spy(fakeServlet(fileItem)); final HttpServletRequest request = requestMock("/plugins/screen"); final HttpServletResponse response = responseMock(); servlet.doPost(request, response); verify(servlet).resolve("/screen/media/image.jpg"); }