public void load() { Set<CoreExtension> coreExtensions = serviceLoaderWrapper.load(getClass().getClassLoader()); ensureNoDuplicateName(coreExtensions); coreExtensionRepository.setLoadedCoreExtensions(coreExtensions); if (!coreExtensions.isEmpty()) { LOG.info("Loaded core extensions: {}", coreExtensions.stream().map(CoreExtension::getName).collect(Collectors.joining(", "))); } }
@Test public void load_sets_loaded_core_extensions_into_repository() { Set<CoreExtension> coreExtensions = IntStream.range(0, 1 + new Random().nextInt(5)) .mapToObj(i -> newCoreExtension("core_ext_" + i)) .collect(Collectors.toSet()); when(serviceLoaderWrapper.load(any())).thenReturn(coreExtensions); underTest.load(); verify(serviceLoaderWrapper).load(CoreExtensionsLoader.class.getClassLoader()); verify(coreExtensionRepository).setLoadedCoreExtensions(coreExtensions); verifyNoMoreInteractions(serviceLoaderWrapper, coreExtensionRepository); }
@Test public void load_has_no_effect_if_there_is_no_ServiceLoader_for_CoreExtension_class() { when(serviceLoaderWrapper.load(any())).thenReturn(Collections.emptySet()); underTest.load(); verify(serviceLoaderWrapper).load(CoreExtensionsLoader.class.getClassLoader()); verify(coreExtensionRepository).setLoadedCoreExtensions(Collections.emptySet()); verifyNoMoreInteractions(serviceLoaderWrapper, coreExtensionRepository); }
public void load() { Set<CoreExtension> coreExtensions = serviceLoaderWrapper.load(getClass().getClassLoader()); ensureNoDuplicateName(coreExtensions); coreExtensionRepository.setLoadedCoreExtensions(coreExtensions); if (!coreExtensions.isEmpty()) { LOG.info("Loaded core extensions: {}", coreExtensions.stream().map(CoreExtension::getName).collect(Collectors.joining(", "))); } }
@Test public void load_fails_with_ISE_if_multiple_core_extensions_declare_same_names() { Set<CoreExtension> coreExtensions = ImmutableSet.of(newCoreExtension("a"), newCoreExtension("a"), newCoreExtension("b"), newCoreExtension("b")); when(serviceLoaderWrapper.load(any())).thenReturn(coreExtensions); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Multiple core extensions declare the following names: a, b"); underTest.load(); }
@Test public void load_fails_with_ISE_if_multiple_core_extensions_declare_same_name() { Set<CoreExtension> coreExtensions = ImmutableSet.of(newCoreExtension("a"), newCoreExtension("a")); when(serviceLoaderWrapper.load(any())).thenReturn(coreExtensions); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Multiple core extensions declare the following names: a"); underTest.load(); }