### Question:
SiteMapFilesCacheImpl extends CacheBuilderBase implements SiteMapFilesCache, SiteMapStructureCache.RefreshListener { @Override public String get(final Resource rootPage, final int index) { final String key = Integer.toString(index); try (final ResourceResolver resourceResolver = getServiceResourceResolver()) { return Optional.ofNullable(rootPage) .filter(ResourceUtils::exists) .map(r -> getCache(resourceResolver, r)) .map(Resource::getValueMap) .map(props -> props.get(key, String.class)) .orElse(null); } catch (final LoginException e) { logger.error(COULD_NOT_GET_SERVICE_RESOURCE_RESOLVER, e); return null; } }  @Activate void activate(final SiteMapFilesCacheImplConfig config); @Deactivate void deactivate(); @Override String get(final Resource rootPage, final int index); @Override void onCacheRefreshed(final Resource rootPage, final List<SiteMapEntry> entries);  }### Answer:
@Test public void get_cacheExists() { when(structureCache.get(page)).thenReturn(Collections.emptyList()); assertNull(model.get(page, 0)); cache.putProperty("0", VALUE); assertEquals(VALUE, model.get(page, 0)); when(structureCache.get(page)).thenReturn(null); assertEquals(VALUE, model.get(page, 0)); when(siteMapExtractorsContainer.findFirstFor(page)).thenReturn(extractor); assertEquals(VALUE, model.get(page, 0)); when(structureCache.get(page)).thenReturn(Collections.emptyList()); assertEquals(VALUE, model.get(page, 0)); }
@Test public void get_handleNullEntriesAndExtractor() { when(structureCache.get(page)).thenReturn(null); assertNull(model.get(page, 0)); when(siteMapExtractorsContainer.findFirstFor(page)).thenReturn(null); assertNull(model.get(page, 0)); when(structureCache.get(page)).thenReturn(Collections.emptyList()); assertNull(model.get(page, 0)); }