### Question:
ExtensionInstaller { public void installExtension(String wikiId, ExtensionId extensionId) throws WikiCreationException { try { InstallRequest installRequest = new InstallRequest(); installRequest.setId(Arrays.asList(WikiCreationJob.JOB_ID_PREFIX, "install", wikiId)); installRequest.addExtension(extensionId); installRequest.addNamespace("wiki:" + wikiId); installRequest.setProperty(PROPERTY_USERREFERENCE, SUPERADMIN_REFERENCE); InstallJob job = componentManager.getInstance(Job.class, InstallJob.JOBTYPE); job.initialize(installRequest); job.run(); } catch (ComponentLookupException e) { throw new WikiCreationException(String.format("Failed to install the extension [%s] on the wiki [%s].", extensionId.toString(), wikiId), e); } }  void installExtension(String wikiId, ExtensionId extensionId);  }### Answer:
@Test public void installExtension() throws Exception { InstallJob installJob = mock(InstallJob.class); mocker.registerComponent(Job.class, InstallJob.JOBTYPE, installJob); final InstallRequest[] installRequest = {null}; doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { installRequest[0] = (InstallRequest) invocation.getArguments()[0]; return null; } }).when(installJob).initialize(any(Request.class)); mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version")); assertNotNull(installRequest[0]); assertEquals(Arrays.asList("wiki:wikiId"), installRequest[0].getNamespaces()); assertEquals(Arrays.asList("wikicreation", "install", "wikiId"), installRequest[0].getId()); assertEquals(Arrays.asList(new ExtensionId("extensionId", "version")), installRequest[0].getExtensions()); assertEquals(new DocumentReference("xwiki", "XWiki", "superadmin"), installRequest[0].getProperty("user.reference")); verify(installJob).run(); }
@Test public void installExtensionWithException() throws Exception { WikiCreationException caughtException = null; try { mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version")); } catch (WikiCreationException e) { caughtException = e; } assertNotNull(caughtException); assertEquals("Failed to install the extension [extensionId/version] on the wiki [wikiId].", caughtException.getMessage()); assertTrue(caughtException.getCause() instanceof ComponentLookupException); }