### Question:
CustomSendErrorFilter extends SendErrorFilter { @Override public Object run() { try { RequestContext ctx = RequestContext.getCurrentContext(); ExceptionHolder exception = findZuulException(ctx.getThrowable()); HttpServletRequest request = ctx.getRequest(); request.setAttribute("javax.servlet.error.status_code", exception.getStatusCode()); request.setAttribute("javax.servlet.error.exception", exception.getThrowable()); if (StringUtils.hasText(exception.getErrorCause())) { request.setAttribute("javax.servlet.error.message", exception.getErrorCause()); } RequestDispatcher dispatcher = request.getRequestDispatcher(this.errorPath); if (dispatcher != null) { ctx.set(SEND_ERROR_FILTER_RAN, true); if (!ctx.getResponse().isCommitted()) { ctx.setResponseStatusCode(exception.getStatusCode()); dispatcher.forward(request, ctx.getResponse()); } } } catch (Exception ex) { ReflectionUtils.rethrowRuntimeException(ex); } return null; } CustomSendErrorFilter(@Value("${error.path:/error}") String errorPath); @Override int filterOrder(); @Override Object run(); @Override void setErrorPath(String errorPath); static final String ERROR_FILTER_RAN; }### Answer:
@Test void givenFilter_whenRun_thenNoErrors() { Object result = filter.run(); assertNull(result); }
@Test void givenFilterNoErrorPath_whenRun_thenErrorWithDispatcher() { filter = new CustomSendErrorFilter(null); Exception ex = assertThrows(IllegalArgumentException.class, () -> filter.run()); assertEquals("Resource must not be null", ex.getMessage()); }