### Question:
AjaxUploadDecoderImpl implements AjaxUploadDecoder { @Override public void setupUploadedFile(HttpServletRequest request) { String fieldName = request.getHeader(AJAX_UPLOAD_HEADER); FileItem item = fileItemFactory.createItem(fieldName, request.getContentType(), false, request.getParameter(AjaxUploadConstants.FILE_PARAMETER)); try { TapestryInternalUtils.copy(request.getInputStream(), item.getOutputStream()); } catch (IOException e) { throw new RuntimeException("Could not copy request's input stream to file", e); } uploadedFile = new UploadedFileItem(item); } AjaxUploadDecoderImpl(FileItemFactory fileItemFactory); @Override boolean isAjaxUploadRequest(HttpServletRequest request); @Override boolean isAjaxUploadRequest(Request request); @Override void setupUploadedFile(HttpServletRequest request); @Override UploadedFile getFileUpload(); static final String AJAX_UPLOAD_HEADER; }### Answer:
@Test public void check_new_uploaded_file_is_created_during_setup() throws Exception { HttpServletRequest request = mockHttpServletRequest(); FileItem item = mockFileItem(); ServletInputStream inputStream = newStringInputStream("Test stream data"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); expect(request.getHeader(AjaxUploadDecoderImpl.AJAX_UPLOAD_HEADER)).andReturn("test"); expect(request.getContentType()).andReturn("test/test"); expect(request.getParameter(AjaxUploadConstants.FILE_PARAMETER)).andReturn("myfilename"); expect(request.getInputStream()).andReturn(inputStream); expect(fileItemFactory.createItem("test", "test/test", false, "myfilename")).andReturn(item); expect(item.getOutputStream()).andReturn(outputStream); replay(); decoder.setupUploadedFile(request); verify(); assertEquals(outputStream.toString(), "Test stream data"); }