UserNameOverrideFilter implements Filter { protected Matcher getUserNameMatcher(String requestUri) { return USER_NAME_IN_URI_REGEXP.matcher(requestUri); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }
@Test public void testGetUserNameMatcherNoUserNameInUri() throws Exception { String uri = "/aaa/bbb"; Matcher m = filter.getUserNameMatcher(uri); boolean isMatch = m.matches(); assertFalse(isMatch); }
@Test public void testGetUserNameMatcherNoPostInUri() throws Exception { String uri = "/aaa/users/user1@domain"; Matcher m = filter.getUserNameMatcher(uri); boolean isMatch = m.find(); String pre = isMatch ? m.group("pre") : null; String userName = isMatch ? m.group("username") : null; String post = isMatch ? m.group("post") : null; assertTrue(isMatch); assertEquals("/aaa/users/", pre); assertEquals("user1@domain", userName); assertEquals("", post); }
@Test public void testGetUserNameMatcherPostInUri() throws Exception { String uri = "/aaa/users/user1@domain/privileges"; Matcher m = filter.getUserNameMatcher(uri); boolean isMatch = m.find(); String pre = isMatch ? m.group("pre") : null; String userName = isMatch ? m.group("username") : null; String post = isMatch ? m.group("post") : null; assertTrue(isMatch); assertEquals("/aaa/users/", pre); assertEquals("user1@domain", userName); assertEquals("/privileges", post); }