private void assertExcluded(boolean excluded, String requestURI) throws Exception {
assertExcluded(excluded, requestURI, false);
}
private void assertExcluded(boolean excluded, String requestURI, boolean internal) throws Exception {
RequestURIFilter excludes = getFieldValue(filter, "excludeFilter", RequestURIFilter.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);
FilterChain filterChain = createMock(FilterChain.class);
// 不会调用getContextPath和getRequestURI
expect(request.getServletPath()).andReturn(requestURI).anyTimes();
expect(request.getPathInfo()).andReturn(null).anyTimes();
if (excluded && !internal) {
filterChain.doFilter(request, response);
}
replay(request, response, filterChain);
if (internal) {
assertFalse(filter.isExcluded(getResourcePath(request)));
} else {
assertEquals(excluded, excludes.matches(requestURI));
}
if (excluded && !internal) {
filter.doFilter(request, response, filterChain); // 对excluded request调用doFilter,应该立即返回
assertTrue(filter.isExcluded(getResourcePath(request)));