title: Mockito in order verify with any matchers
body: <p>I'm having some issues testing a servlet filter. The purpose of this servlet filter is to populate some http headers on response after the filterChain has been executed.  So what I am trying to test is that setHeader calls on my mockHttpServletResponse don't happen until after mockFilterChain.doFilter is called.</p>
  
  <p>I am  using mockito:mockito-core:1.8.5</p>
  
  <p>So, here is a sample code snippet</p>
  
  <pre><code>@Test
  public void filterHeaderInjectionHappensLast() throws Exception {
      javax.servlet.Filter myFilter = new HeaderInjectionFilter();
  
      mockRequest = mock(javax.servlet.http.HttpServletRequest.class);
      mockResponse = mock(javax.servlet.http.HttpServletResponse.class);
      mockFilterChain = mock(javax.servlet.FilterChain.class);
  
      myFilter.doFilter(mockRequest, mockResponse, mockFilterChain);
  
      InOrder inOrder = inOrder(mockFilterChain, mockResponse);
      inOrder.verify(mockFilterChain).doFilter(mockRequest,mockResponse);
      inOrder.verify(mockResponse).setHeader(any(String.class),any(String.class));    
  }
  </code></pre>
  
  <p>That test will fail do to the verify of setHeader passing any string arguments. If I change that setHeader verification call to accept specific arguments that are used in the code the test will pass successfully.  Can you not use wildcard matchers when you are verifying order like this?</p>
  
  <p>HeaderInjectionFilter dumbed down looks like this</p>
  
  <pre><code>public class HeaderInjectionFilter implements Filter {
      @Override
      public void destroy() {}
  
      @Override
      public void init(FilterConfig filterConfig) throws ServletException {}
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
          filterChain.doFilter(request, response); //Always doFilter before we add header to response
  
          HttpServletResponse httpServletResponse = (HttpServletResponse) response;
          httpServletResponse.setHeader(CACHE_CONTROL, "no-cache");
          httpServletResponse.setHeader(PRAGMA, "no-cache");
      }
  }
  </code></pre>