### Question:
DefaultWikiManager implements WikiManager { @Override public WikiDescriptor create(String wikiId, String wikiAlias, boolean failOnExist) throws WikiManagerException { return create(wikiId, wikiAlias, null, failOnExist); }  @Override WikiDescriptor create(String wikiId, String wikiAlias, boolean failOnExist); @Override WikiDescriptor create(String wikiId, String wikiAlias, String ownerId, boolean failOnExist); @Override WikiDescriptor copy(String fromWikiId, String newWikiId, String newWikiAlias, boolean copyHistory,
        boolean copyRecycleBin, boolean failOnExist); @Override WikiDescriptor rename(String wikiId, String newWikiId); @Override void delete(String wikiId); @Override boolean idAvailable(String wikiId);  }### Answer:
@Test public void createWhenWikiExists() throws Exception { when(wikiDescriptorManager.exists("wikiid1")).thenReturn(true); boolean exceptionCaught = false; try { this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1", true); } catch (WikiManagerException e) { exceptionCaught = true; } assertTrue(exceptionCaught); }
@Test public void createWhenWikiIdIsForbidden() throws Exception { when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false); when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden,wikiid1"); boolean exceptionCaught = false; try { this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1", true); } catch (WikiManagerException e) { exceptionCaught = true; } assertTrue(exceptionCaught); }
@Test public void createWhenWikiIdIsValid() throws Exception { when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false); when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden"); when(store.isWikiNameAvailable(eq("wikiid1"), any(XWikiContext.class))).thenReturn(true); DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1", "owner"); when(wikiCreator.create("wikiid1", "wikialias1", "owner")).thenReturn(descriptor); WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1", "owner", true); assertNotNull(newWikiDescriptor); assertTrue(newWikiDescriptor instanceof DefaultWikiDescriptor); verify(wikiCreator).create("wikiid1", "wikialias1", "owner"); verify(observationManager).notify(new WikiCreatingEvent("wikiid1"), "wikiid1", xcontext); verify(observationManager).notify(new WikiCreatedEvent("wikiid1"), "wikiid1", xcontext); }
@Test public void createWhenWikiIdIsValidButFail() throws Exception { when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false); when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden"); when(store.isWikiNameAvailable(eq("wikiid1"), any(XWikiContext.class))).thenReturn(true); DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1", "owner"); when(wikiCreator.create("wikiid1", "wikialias1", "owner")).thenThrow(new WikiManagerException("...")); boolean exceptionCaught = false; try { this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1", "owner", true); } catch (WikiManagerException e) { exceptionCaught = true; } assertTrue(exceptionCaught); verify(observationManager).notify(new WikiCreatingEvent("wikiid1"), "wikiid1", xcontext); verify(observationManager).notify(new WikiCreateFailedEvent("wikiid1"), "wikiid1", xcontext); }