ApiAccessRejectionFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; resp.setStatus(500); resp.getOutputStream().write(ERROR_MESSAGE_IN_BYTES); }  @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void init(FilterConfig filterConfig); @Override void destroy(); static final String ERROR_MESSAGE; }
@Test public void shouldReturnError() throws Exception { when(response.getOutputStream()).thenReturn(outputStream); filter.doFilter(request, response, chain); verifyZeroInteractions(chain); verify(response).setStatus(500); verify(outputStream).write(eq(ApiAccessRejectionFilter.ERROR_MESSAGE.getBytes())); }