### Question:
SlashFilter extends ZuulFilter { @Override public boolean shouldFilter() { RequestContext context = RequestContext.getCurrentContext(); String url = context.getRequest().getRequestURL().toString().toLowerCase(); String serviceId = (String) context.get(SERVICE_ID_KEY); String proxy = (String) context.get(PROXY_KEY); boolean checkProxy = (proxy != null) && REGEX_CONTAINS_UI_PATH.matcher(proxy).find(); boolean checkServiceId = (serviceId != null) && !serviceId.isEmpty() && url.contains(serviceId); boolean oldPathFormatShouldFilter = checkServiceId && url.endsWith(serviceId); boolean newPathFormatShouldFilter = checkProxy && REGEX_END_WITH_UI_ROUTE.matcher(url).find(); return checkProxy && checkServiceId && (oldPathFormatShouldFilter || newPathFormatShouldFilter); }  @Override boolean shouldFilter(); @Override String filterType(); @Override int filterOrder(); @Override Object run();  }### Answer:
@Test void shouldFilterUI() { assertTrue(this.filter.shouldFilter()); }
@Test void shouldNotFilterAPI() { final RequestContext ctx = RequestContext.getCurrentContext(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setRequestURI("/service/api/v1"); ctx.set(PROXY_KEY, "/service/api/v1"); ctx.setRequest(mockRequest); assertFalse(this.filter.shouldFilter()); }
@Test void shouldNotFilterAPI_OldPathFormat() { final RequestContext ctx = RequestContext.getCurrentContext(); setRequestContextToOldPathFormat(ctx); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setRequestURI("/api/v1/service"); ctx.set(PROXY_KEY, "/api/v1/service"); ctx.setRequest(mockRequest); assertFalse(this.filter.shouldFilter()); }
@Test void shouldNotFilterWhenItEndsWithSlash() { final RequestContext ctx = RequestContext.getCurrentContext(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setRequestURI("/service/ui/"); ctx.setRequest(mockRequest); assertFalse(this.filter.shouldFilter()); }
@Test void shouldNotFilterWhenItEndsWithSlash_OldPathFormat() { final RequestContext ctx = RequestContext.getCurrentContext(); setRequestContextToOldPathFormat(ctx); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setRequestURI("/ui/service/"); ctx.setRequest(mockRequest); assertFalse(this.filter.shouldFilter()); }
@Test void serviceIdIsNull() { final RequestContext ctx = RequestContext.getCurrentContext(); ctx.set(SERVICE_ID_KEY, null); assertFalse(this.filter.shouldFilter()); }
@Test void serviceIdIsEmpty() { final RequestContext ctx = RequestContext.getCurrentContext(); ctx.set(SERVICE_ID_KEY, ""); assertFalse(this.filter.shouldFilter()); }