### Question:
CacheBuilderBase implements CacheBuilder { protected final Resource getCache(final ResourceResolver resourceResolver, final Resource rootPage) { if (!isCached(resourceResolver, rootPage.getPath())) { try { final Resource cache = buildCache(resourceResolver, rootPage); resourceResolver.commit(); return cache; } catch (final PersistenceException e) { logger.error(COULD_NOT_SAVE_SITE_MAP_CACHE, e); } } final String path = getCachePath(rootPage); return resourceResolver.getResource(path); }  final String getOriginalPath(final String cachePath); @Override final void rebuild(final String rootPagePath); @Override void rebuildAll();  }### Answer:
@Test public void getCache_existsAlready() { final Resource cache = model.getCache(resourceResolver, parent); assertEquals(parentCache, cache); assertTrue(buildCacheCalled.isEmpty()); }
@Test public void getCache_doesNotExistYet() { disableResolution(parentCache); final Resource cache = model.getCache(resourceResolver, parent); assertNotEquals(parentCache, cache); verifyCommits(1); assertTrue(buildCacheCalled.containsKey(parent)); assertEquals(cache, buildCacheCalled.get(parent)); }
@SuppressWarnings("unchecked") @Test public void getCache_doesNotExistYet_handlePersistenceException() throws PersistenceException { disableResolution(parentCache); when(resourceResolver.create(any(), any(), any())).thenThrow(PersistenceException.class); final Resource cache = model.getCache(resourceResolver, parent); assertNull(cache); verifyCommits(1); assertTrue(buildCacheCalled.isEmpty()); }