### Question:
VanityURLServiceImpl implements VanityURLService { public boolean dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException, RepositoryException { if (request.getAttribute(VANITY_DISPATCH_CHECK_ATTR) != null) { log.trace("Processing a previously vanity dispatched request. Skipping..."); return false; } request.setAttribute(VANITY_DISPATCH_CHECK_ATTR, true); final String requestURI = request.getRequestURI(); final PathInfo pathInfo = new PathInfo(request.getResourceResolver(), requestURI); String candidateVanity = pathInfo.getResourcePath(); if (request.getResourceResolver().resolve(requestURI) == null) { candidateVanity = request.getResourceResolver().map(request, candidateVanity); } log.trace("Generated Candidate Vanity URL from the mapping of [ {} -> {} ]", requestURI, candidateVanity); final String pathScope = StringUtils.removeEnd(requestURI, candidateVanity); log.debug("Candidate vanity URL to check and dispatch: [ {} ]", candidateVanity); if (vanityUrlAdjuster != null) { final String originalCandidateVanity = candidateVanity; candidateVanity = vanityUrlAdjuster.adjust(request, candidateVanity); log.debug("Custom adjustment of candidate vanity [ {} -> {} ]", originalCandidateVanity, candidateVanity); } if (!StringUtils.equals(candidateVanity, requestURI) && isVanityPath(pathScope, candidateVanity, request)) { log.debug("Forwarding request to vanity resource [ {} ]", candidateVanity); final RequestDispatcher requestDispatcher = request.getRequestDispatcher(candidateVanity); requestDispatcher.forward(new ExtensionlessRequestWrapper(request), response); return true; } return false; }  boolean dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response);  }### Answer:
@Test public void dispatch_NoMapping() throws Exception { ctx.request().setServletPath("/my-vanity"); assertFalse(vanityURLService.dispatch(ctx.request(), ctx.response())); verify(requestDispatcher, times(0)).forward(any(ExtensionlessRequestWrapper.class), eq(ctx.response())); }
@Test public void dispatch_Loop() throws Exception { ctx.request().setAttribute("acs-aem-commons__vanity-check-loop-detection", true); assertFalse(vanityURLService.dispatch(ctx.request(), ctx.response())); verify(requestDispatcher, times(0)).forward(any(ExtensionlessRequestWrapper.class), eq(ctx.response())); }