Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CARROT-1276: Allow multiple classloader SPI resolution in language co…
…mponents loader
- Loading branch information
Showing
2 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/src/test/java/org/carrot2/language/LanguageComponentsLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Carrot2 project. | ||
* | ||
* Copyright (C) 2002-2020, Dawid Weiss, Stanisław Osiński. | ||
* All rights reserved. | ||
* | ||
* Refer to the full license file "carrot2.LICENSE" | ||
* in the root folder of the repository checkout or at: | ||
* https://www.carrot2.org/carrot2.LICENSE | ||
*/ | ||
package org.carrot2.language; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import org.assertj.core.api.Assertions; | ||
import org.carrot2.TestBase; | ||
import org.junit.Test; | ||
|
||
public class LanguageComponentsLoaderTest extends TestBase { | ||
@Test | ||
public void testMultipleSpiDeduplicatesProviders() { | ||
Map<String, List<LanguageComponentsProvider>> langs = | ||
LanguageComponentsLoader.loadProvidersFromSpi( | ||
getClass().getClassLoader(), getClass().getClassLoader()); | ||
|
||
for (List<LanguageComponentsProvider> perLangProviders : langs.values()) { | ||
perLangProviders.stream() | ||
.collect(Collectors.groupingBy(LanguageComponentsProvider::getClass)) | ||
.values() | ||
.forEach( | ||
providersByClass -> { | ||
Assertions.assertThat(providersByClass).hasSize(1); | ||
}); | ||
} | ||
} | ||
} |