### Question:
DefaultWikiDescriptorManager implements WikiDescriptorManager { @Override public WikiDescriptor getById(String wikiId) throws WikiManagerException { WikiDescriptor descriptor = cache.getFromId(wikiId); if (descriptor == null) { XWikiDocument document = descriptorDocumentHelperProvider.get().getDocumentFromWikiId(wikiId); if (!document.isNew()) { descriptor = buildDescriptorFromDocument(document); } else if (getMainWikiId().equals(wikiId)) { descriptor = new WikiDescriptor(wikiId, "localhost"); } if (descriptor == null) { cache.addFromId(wikiId, DefaultWikiDescriptor.VOID); } } return descriptor != DefaultWikiDescriptor.VOID && descriptor != null ? descriptor.clone() : null; }  @Override Collection<WikiDescriptor> getAll(); @Override Collection<String> getAllIds(); @Override WikiDescriptor getByAlias(String wikiAlias); @Override WikiDescriptor getById(String wikiId); @Override boolean exists(String wikiId); @Override void saveDescriptor(WikiDescriptor descriptor); @Override WikiDescriptor getMainWikiDescriptor(); @Override String getMainWikiId(); @Override boolean isMainWiki(String wikiId); @Override String getCurrentWikiId(); @Override WikiReference getCurrentWikiReference(); @Override WikiDescriptor getCurrentWikiDescriptor();  }### Answer:
@Test void getByIdWhenNotInCacheButExists() throws Exception { when(this.cache.getFromId("wikiid")).thenReturn(null); XWikiDocument document = mock(XWikiDocument.class); when(this.descriptorDocumentHelper.getDocumentFromWikiId("wikiid")).thenReturn(document); when(document.isNew()).thenReturn(false); List<BaseObject> baseObjects = Arrays.asList(mock(BaseObject.class)); when(document.getXObjects(any(EntityReference.class))).thenReturn(baseObjects); DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias"); when(this.wikiDescriptorBuilder.buildDescriptorObject(anyList(), any(XWikiDocument.class))) .thenReturn(descriptor); assertEquals(descriptor, this.descriptorManager.getById("wikiid")); verify(this.cache).add(descriptor); }
@Test void getByIdWhenInCache() throws Exception { DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias"); when(this.cache.getFromId("wikiid")).thenReturn(descriptor); assertEquals(descriptor, this.descriptorManager.getById("wikiid")); }
@Test void getByIdWhenNotInCacheAndItDoesntExist() throws Exception { XWikiDocument document = mock(XWikiDocument.class); when(this.descriptorDocumentHelper.getDocumentFromWikiId("wikiid")).thenReturn(document); when(document.isNew()).thenReturn(true); assertNull(this.descriptorManager.getById("wikiid")); verify(this.cache).addFromId(eq("wikiid"), same(DefaultWikiDescriptor.VOID)); }