### Question:
ESProxyFilter implements Filter { protected String rewriteRequestUrl(HttpServletRequest servletRequest, URI targetUri) { StringBuilder uri = new StringBuilder(500); uri.append(targetUri); String path = servletRequest.getRequestURI(); if (!SearchUtils.isBlank(path)) { String[] pe = path.split("/"); int matchcount = 5; for (int i = 0; i < pe.length; i++) { if ("sys".equals(pe[i])) { matchcount = i + 2; } if (i > matchcount) { uri.append("/"); uri.append(pe[i]); } } } String queryString = servletRequest.getQueryString(); if (!SearchUtils.isBlank(queryString)) { uri.append('?'); uri.append(queryString); } return uri.toString(); }  @Override void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }### Answer:
@Test public void rewriteRequestUrl() throws URISyntaxException { ESProxyFilter tested = getTested(); URI targetUri = new URI("http: HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class); Assert.assertEquals("http: Mockito.when(servletRequest.getRequestURI()).thenReturn("/v2/rest/sys/es/search"); Assert.assertEquals("http: Mockito.when(servletRequest.getRequestURI()).thenReturn("/v2/rest/sys/es/search/"); Assert.assertEquals("http: Mockito.when(servletRequest.getRequestURI()).thenReturn("/v2/rest/sys/es/search/_all"); Assert.assertEquals("http: Mockito.when(servletRequest.getRequestURI()).thenReturn("/v2/rest/sys/es/stats/_all/mytype"); Assert.assertEquals("http: Mockito.when(servletRequest.getRequestURI()).thenReturn("/context/v2/rest/sys/es/stats/_all/mytype"); Assert.assertEquals("http: }