### Question:
AjaxUploadDecoderImpl implements AjaxUploadDecoder { @Override public boolean isAjaxUploadRequest(HttpServletRequest request) { return request.getHeader(AJAX_UPLOAD_HEADER) != null; } 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_ajax_upload_request_calls_decoder() { Request request = mockRequest(); expect(request.getHeader(AjaxUploadDecoderImpl.AJAX_UPLOAD_HEADER)).andReturn("test"); expect(request.isXHR()).andReturn(true); replay(); assertTrue(decoder.isAjaxUploadRequest(request)); verify(); }
@Test public void check_ajax_upload_request_calls_decoder_with_http_servlet_request() { HttpServletRequest request = mockHttpServletRequest(); expect(request.getHeader(AjaxUploadDecoderImpl.AJAX_UPLOAD_HEADER)).andReturn("test"); replay(); assertTrue(decoder.isAjaxUploadRequest(request)); verify(); }
@Test public void check_ajax_request_does_not_call_decoder_if_header_not_present() { Request request = mockRequest(); expect(request.isXHR()).andReturn(true); expect(request.getHeader(AjaxUploadDecoderImpl.AJAX_UPLOAD_HEADER)).andReturn(null); replay(); assertFalse(decoder.isAjaxUploadRequest(request)); verify(); }
@Test public void check_non_ajax_request_does_not_call_decoder_if_header_not_present() { Request request = mockRequest(); expect(request.isXHR()).andReturn(false); replay(); assertFalse(decoder.isAjaxUploadRequest(request)); verify(); }
@Test public void check_request_does_not_call_decoder_if_header_not_present_with_http_servlet_request() { HttpServletRequest request = mockHttpServletRequest(); expect(request.getHeader(AjaxUploadDecoderImpl.AJAX_UPLOAD_HEADER)).andReturn(null); replay(); assertFalse(decoder.isAjaxUploadRequest(request)); verify(); }