### Question:
ResourceUtils { public static Resource getFirstExistingAncestorOnPath(final ResourceResolver resourceResolver, final String path) { String existingPath = path; Resource resource = null; while (StringUtils.isNotBlank(existingPath) && (resource = resourceResolver.getResource(existingPath)) == null) { existingPath = StringUtils.substringBeforeLast(existingPath, SLASH); } if (isNull(resource)) { return resourceResolver.getResource(SLASH); } return resource; } private  ResourceUtils(); static Resource getJcrContent(final Resource resource); static Resource getFirstExistingAncestorOnPath(final ResourceResolver resourceResolver, final String path); static Resource getOrCreateResource(
            final ResourceResolver resourceResolver,
            final String path,
            final String resourceTypes); static String fileNameToJcrName(final String name); static String jcrNameToFileName(final String name); static boolean exists(final Resource resource); static L removeDuplicates(final L list);  }### Answer:
@Test public void getFirstExistingAncestorOnPath_emptyPath() { final Resource resource = ResourceUtils.getFirstExistingAncestorOnPath(resourceResolver, null); assertEquals(repo.getRoot(), resource); }
@Test public void getFirstExistingAncestorOnPath_noResourceUnderPath() { when(resourceResolver.getResource(path)).thenReturn(null); final Resource resource = ResourceUtils.getFirstExistingAncestorOnPath(resourceResolver, path); assertEquals(jcrContent, resource); }
@Test public void getFirstExistingAncestorOnPath_findResource() { final Resource resource = ResourceUtils.getFirstExistingAncestorOnPath(resourceResolver, path); assertEquals(this.resource, resource); }