### Question:
ResourceUtils { public static Resource getOrCreateResource( final ResourceResolver resourceResolver, final String path, final String resourceTypes) throws PersistenceException { if (isBlank(path)) { return null; } Resource resource = getFirstExistingAncestorOnPath(resourceResolver, path); final String missingPath; if (isNull(resource)) { missingPath = path; } else { missingPath = StringUtils.substringAfter(path, resource.getPath()); } final String[] missing = StringUtils.split(missingPath, SLASH); final Map<String, Object> properties = new HashMap<>(); properties.put(JCR_PRIMARY_TYPE, resourceTypes); for (final String name : missing) { resource = resourceResolver.create(resource, name, properties); } return resourceResolver.getResource(path); } 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 getOrCreateResource_resourceAlreadyExists() throws PersistenceException { final Resource resource = ResourceUtils.getOrCreateResource(resourceResolver, path, null); assertEquals(this.resource, resource); }
@Test public void getOrCreateResource_resourceGetsCreated() throws PersistenceException { when(resourceResolver.getResource(path)).thenReturn(null); when(resourceResolver.create(eq(jcrContent), eq(NN_RESOURCE), any())).thenAnswer(invocation -> { when(resourceResolver.getResource(path)).thenReturn(resource); return resource; }); final Resource resource = ResourceUtils.getOrCreateResource(resourceResolver, path, null); assertEquals(this.resource, resource); }