### Question:
VanityURLServiceImpl implements VanityURLService { protected boolean isVanityPath(String pathScope, String vanityPath, SlingHttpServletRequest request) throws RepositoryException { final Resource vanityResource = request.getResourceResolver().resolve(vanityPath); if (vanityResource != null) { String targetPath = null; if (vanityResource.isResourceType("sling:redirect")) { targetPath = vanityResource.getValueMap().get("sling:target", String.class); } else if (!StringUtils.equals(vanityPath, vanityResource.getPath())) { targetPath = vanityResource.getPath(); } if (targetPath != null && StringUtils.startsWith(targetPath, StringUtils.defaultIfEmpty(pathScope, DEFAULT_PATH_SCOPE))) { log.debug("Found vanity resource at [ {} ] for sling:vanityPath [ {} ]", targetPath, vanityPath); return true; } } return false; }  boolean dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response);  }### Answer:
@Test public void isVanityPath() throws Exception { ctx.build().resource("/foo", "jcr:primaryType", "sling:redirect", "sling:target", "/content/bar"); assertTrue(vanityURLService.isVanityPath("/content", "/foo", ctx.request())); }
@Test public void isVanityPath_OutsideOfPathScope() throws Exception { ctx.build().resource("/foo", "jcr:primaryType", "sling:redirect", "sling:target", "/bar"); assertFalse(vanityURLService.isVanityPath("/content", "/foo", ctx.request())); }
@Test public void isVanityPath_NotRedirectResource() throws Exception { ctx.build().resource("/foo", "jcr:primaryType", "nt:unstructured"); assertFalse(vanityURLService.isVanityPath("/content", "/foo", ctx.request())); }