Use same default ClassLoader in SpringFactoriesLoader
Prior to this commit, the loadFactoryNames() and loadFactories() methods in SpringFactoriesLoader effectively used a different default ClassLoader. This commit ensures that the ClassLoader for SpringFactoriesLoader.class is now consistently used as the default ClassLoader. Closes gh-24992
This commit is contained in:
@@ -19,6 +19,8 @@ package org.springframework.core.io.support;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -33,6 +35,23 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
class SpringFactoriesLoaderTests {
|
||||
|
||||
@BeforeAll
|
||||
static void clearCache() {
|
||||
SpringFactoriesLoader.cache.clear();
|
||||
assertThat(SpringFactoriesLoader.cache).isEmpty();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void checkCache() {
|
||||
assertThat(SpringFactoriesLoader.cache).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadFactoryNames() {
|
||||
List<String> factoryNames = SpringFactoriesLoader.loadFactoryNames(DummyFactory.class, null);
|
||||
assertThat(factoryNames).containsExactlyInAnyOrder(MyDummyFactory1.class.getName(), MyDummyFactory2.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadFactoriesWithNoRegisteredImplementations() {
|
||||
List<Integer> factories = SpringFactoriesLoader.loadFactories(Integer.class, null);
|
||||
|
||||
Reference in New Issue
Block a user