DefaultExtensionManager implements ExtensionManager, Initializable { @Override public Extension resolveExtension(ExtensionId extensionId) throws ResolveException { try { return this.coreExtensionRepository.resolve(extensionId); } catch (ResolveException notACoreExtension) { return resolveExtensionFromInstalled(extensionId); } }  @Override void initialize(); @Override Extension resolveExtension(ExtensionId extensionId); @Override @Deprecated Extension resolveExtension(ExtensionDependency extensionDependency); @Override Extension resolveExtension(ExtensionDependency extensionDependency, String namespace); @Override ExtensionRepository getRepository(String repositoryId); @Override Extension getAccessibleExtension(String feature, Namespace namespace); @Override IterableResult<Extension> searchAccessibleExtensions(Namespace namespace, ExtensionQuery query);  }
@Test public void resolveMissingExtensionDependencyOnNamespace() throws Exception { ExtensionDependency extensionDependency = mock(ExtensionDependency.class); doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionDependency); doThrow(ResolveException.class).when(this.localExtensionRepository).resolve(extensionDependency); assertNull(this.mocker.getComponentUnderTest().resolveExtension(extensionDependency, "wiki:math")); }
@Test public void resolveInstalledExtensionDependencyOnNamespace() throws Exception { String namespace = "wiki:math"; String extensionId = "test:extension"; ExtensionDependency extensionDependency = mock(ExtensionDependency.class); doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionDependency); InstalledExtension extension = mock(InstalledExtension.class); when(extensionDependency.getId()).thenReturn(extensionId); when(this.installedExtensionRepository.getInstalledExtension(extensionId, namespace)).thenReturn(extension); Version version = mock(Version.class); when(extension.getId()).thenReturn(new ExtensionId(extensionId, version)); VersionConstraint versionConstraint = mock(VersionConstraint.class); when(extensionDependency.getVersionConstraint()).thenReturn(versionConstraint); when(versionConstraint.containsVersion(version)).thenReturn(true); assertSame(extension, this.mocker.getComponentUnderTest().resolveExtension(extensionDependency, namespace)); }
@Test public void resolveInstalledExtensionId() throws Exception { ExtensionId extensionId = new ExtensionId("extension", "version"); doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionId); InstalledExtension extension = mock(InstalledExtension.class); when(this.installedExtensionRepository.resolve(extensionId)).thenReturn(extension); when(extension.getId()).thenReturn(extensionId); assertSame(extension, this.mocker.getComponentUnderTest().resolveExtension(extensionId)); }