### Question:
SaveWikiMetaDataStep implements WikiCreationStep { @Override public void execute(WikiCreationRequest request) throws WikiCreationException { try { String wikiId = request.getWikiId(); WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId); descriptor.setDescription(request.getDescription()); descriptor.setPrettyName(request.getPrettyName()); wikiDescriptorManager.saveDescriptor(descriptor); wikiTemplateManager.setTemplate(wikiId, request.isTemplate()); wikiUserManager.setUserScope(wikiId, request.getUserScope()); wikiUserManager.setMembershipType(wikiId, request.getMembershipType()); } catch (WikiManagerException | WikiTemplateManagerException | WikiUserManagerException e) { throw new WikiCreationException( String.format("Failed to set metadata to the wiki [%s].", request.getWikiId()), e); } }  @Override void execute(WikiCreationRequest request); @Override int getOrder();  }### Answer:
@Test public void execute() throws Exception { WikiCreationRequest request = new WikiCreationRequest(); request.setWikiId("wikiId"); request.setDescription("description"); request.setPrettyName("pretty name"); request.setOwnerId("ownerId"); request.setTemplate(false); request.setUserScope(UserScope.GLOBAL_ONLY); request.setMembershipType(MembershipType.INVITE); request.setWikiSource(WikiSource.EXTENSION); ExtensionId extensionId = new ExtensionId("id", "version"); request.setExtensionId(extensionId); WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias"); when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor); mocker.getComponentUnderTest().execute(request); assertEquals("description", descriptor.getDescription()); assertEquals("pretty name", descriptor.getPrettyName()); verify(wikiDescriptorManager).saveDescriptor(descriptor); verify(wikiTemplateManager).setTemplate("wikiId", false); verify(wikiUserManager).setUserScope("wikiId", UserScope.GLOBAL_ONLY); verify(wikiUserManager).setMembershipType("wikiId", MembershipType.INVITE); }
@Test public void executeWithException() throws Exception { WikiCreationRequest request = new WikiCreationRequest(); request.setWikiId("wikiId"); WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias"); when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor); Exception exception = new WikiManagerException("Exception on WikiManager."); doThrow(exception).when(wikiDescriptorManager).saveDescriptor(descriptor); WikiCreationException caughtException = null; try { mocker.getComponentUnderTest().execute(request); } catch (WikiCreationException e) { caughtException = e; } assertEquals("Failed to set metadata to the wiki [wikiId].", caughtException.getMessage()); assertEquals(exception, caughtException.getCause()); }
@Test public void executeWhenSourceIsTemplate() throws Exception { WikiCreationRequest request = new WikiCreationRequest(); request.setWikiId("wikiId"); request.setTemplate(false); request.setUserScope(UserScope.LOCAL_ONLY); request.setMembershipType(MembershipType.OPEN); request.setWikiSource(WikiSource.TEMPLATE); WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias"); when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor); mocker.getComponentUnderTest().execute(request); verify(wikiDescriptorManager).saveDescriptor(descriptor); verify(wikiUserManager).setUserScope("wikiId", UserScope.LOCAL_ONLY); verify(wikiUserManager).setMembershipType("wikiId", MembershipType.OPEN); }