GraniteUi { public static @Nullable Page getContentPage(@NotNull HttpServletRequest request) { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request; Resource contentResource = getContentResourceOrParent(request); if (contentResource != null) { PageManager pageManager = slingRequest.getResourceResolver().adaptTo(PageManager.class); if (pageManager != null) { return pageManager.getContainingPage(contentResource); } } return null; } private  GraniteUi(); static @Nullable Resource getContentResource(@NotNull HttpServletRequest request); static @Nullable Resource getContentResourceOrParent(@NotNull HttpServletRequest request); static @Nullable Page getContentPage(@NotNull HttpServletRequest request); static @Nullable String getExistingResourceType(@NotNull ResourceResolver resourceResolver, @NotNull String @NotNull... resourceTypes);  }
@Test void testGetContentPage() { assertSame(page, GraniteUi.getContentPage(request)); }
@Test void testGetContentPage_NoResource() { when(resourceResolver.getResource(CONTENT_PATH)).thenReturn(null); assertNull(GraniteUi.getContentPage(request)); }