Utils { @NotNull public static String getURL(@NotNull SlingHttpServletRequest request, @NotNull PageManager pageManager, @NotNull String path) { Page page = pageManager.getPage(path); if (page != null) { return getURL(request, page); } return path; } private  Utils(); @NotNull static String getURL(@NotNull SlingHttpServletRequest request, @NotNull PageManager pageManager, @NotNull String path); @NotNull static String getURL(@NotNull SlingHttpServletRequest request, @NotNull Page page); static String generateId(String prefix, String path); @NotNull static Set<String> getPageResourceTypes(@NotNull Page page, @NotNull SlingHttpServletRequest request, @NotNull ModelFactory modelFactory); @NotNull static Set<String> getResourceTypes(@NotNull Resource resource, @NotNull SlingHttpServletRequest request, @NotNull ModelFactory modelFactory); @NotNull static Set<String> getXFResourceTypes(@NotNull Resource resource, @NotNull SlingHttpServletRequest request, @NotNull ModelFactory modelFactory); @NotNull static Set<String> getTemplateResourceTypes(@NotNull Page page, @NotNull SlingHttpServletRequest request, @NotNull ModelFactory modelFactory); @NotNull static Set<String> getSuperTypes(@NotNull final String resourceType, @NotNull final ResourceResolver resourceResolver); @NotNull static Set<String> getStrings(@Nullable final Object input); static final String ID_SEPARATOR; static final String COMPONENTS_SERVICE; }
@Test void getURLExtended_pageNull() { String pathSample = "fake/path/for/testing"; when(this.pageManagerMock.getPage(pathSample)) .thenReturn(null); assertEquals(pathSample, Utils.getURL(this.slingHttpServletRequestMock, this.pageManagerMock, pathSample)); }
@Test void getURLExtended_vanityUrlEmpty() { when(this.pageMock.getVanityUrl()) .thenReturn(""); when(this.pageMock.getPath()) .thenReturn("testPage"); when(this.slingHttpServletRequestMock.getContextPath()) .thenReturn("/fake/path/for/testing/"); assertEquals("/fake/path/for/testing/testPage.html", Utils.getURL(this.slingHttpServletRequestMock, this.pageMock)); }
@Test void getURLExtended_vanityUrlCorrect() { when(this.pageMock.getVanityUrl()) .thenReturn("testPage.html"); when(this.slingHttpServletRequestMock.getContextPath()) .thenReturn("/fake/path/for/testing/"); assertEquals("/fake/path/for/testing/testPage.html", Utils.getURL(this.slingHttpServletRequestMock, this.pageMock)); }