### Question:
ContentTypeOverrideFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String contentType = httpServletRequest.getContentType(); if (contentType != null && contentType.startsWith(MediaType.APPLICATION_JSON) && !isUrlExcluded(httpServletRequest.getPathInfo())) { ContentTypeOverrideRequestWrapper requestWrapper = new ContentTypeOverrideRequestWrapper(httpServletRequest); ContentTypeOverrideResponseWrapper responseWrapper = new ContentTypeOverrideResponseWrapper((HttpServletResponse) response); chain.doFilter(requestWrapper, responseWrapper); return; } } chain.doFilter(request, response); }  @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void init(FilterConfig filterConfig); @Override void destroy();  }### Answer:
@Test public void testJSONContentTypeRequest() throws Exception { Vector<String> headers = new Vector<>(1); headers.add(MediaType.APPLICATION_JSON); expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).atLeastOnce(); expect(request.getHeader(HttpHeaders.CONTENT_TYPE)).andReturn(MediaType.APPLICATION_JSON).atLeastOnce(); expect(request.getHeaders(HttpHeaders.CONTENT_TYPE)).andReturn(headers.elements()).atLeastOnce(); replayAll(); FilterChainMock chain = new FilterChainMock(); filter.doFilter(request, response, chain); Assert.assertEquals(MediaType.TEXT_PLAIN, chain.request.getHeader(HttpHeaders.CONTENT_TYPE)); Assert.assertEquals(MediaType.TEXT_PLAIN, chain.request.getHeaders(HttpHeaders.CONTENT_TYPE).nextElement()); verifyAll(); }