diff --git a/spring-context/src/test/java/org/springframework/context/generator/RuntimeHintsPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/generator/RuntimeHintsPostProcessorTests.java index cfd3bfe8699..43a6eb0569a 100644 --- a/spring-context/src/test/java/org/springframework/context/generator/RuntimeHintsPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/generator/RuntimeHintsPostProcessorTests.java @@ -16,10 +16,9 @@ package org.springframework.context.generator; -import java.io.File; -import java.net.MalformedURLException; +import java.io.IOException; import java.net.URL; -import java.net.URLClassLoader; +import java.util.Enumeration; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; @@ -77,7 +76,7 @@ class RuntimeHintsPostProcessorTests { @Test void shouldProcessRegistrarInSpringFactory() { GenericApplicationContext applicationContext = createContext(); - applicationContext.setClassLoader(new TestSpringFactoriesClassLoader()); + applicationContext.setClassLoader(new TestSpringFactoriesClassLoader("test.factories")); this.generator.generateApplicationContext(applicationContext, this.generationContext); assertThatSampleRegistrarContributed(); } @@ -162,19 +161,21 @@ class RuntimeHintsPostProcessorTests { } - private static class TestSpringFactoriesClassLoader extends URLClassLoader { + static class TestSpringFactoriesClassLoader extends ClassLoader { - TestSpringFactoriesClassLoader() { - super(new URL[] {testLocation()}, RuntimeHintsPostProcessorTests.class.getClassLoader()); + private final String factoriesName; + + TestSpringFactoriesClassLoader(String factoriesName) { + super(RuntimeHintsPostProcessorTests.class.getClassLoader()); + this.factoriesName = factoriesName; } - private static URL testLocation() { - try { - return new File("src/test/resources/org/springframework/context/annotation/runtimehints/").toURI().toURL(); - } - catch (MalformedURLException ex) { - throw new IllegalStateException(ex); + @Override + public Enumeration getResources(String name) throws IOException { + if ("META-INF/spring.factories".equals(name)) { + return super.getResources("org/springframework/context/generator/runtimehints/" + this.factoriesName); } + return super.getResources(name); } } diff --git a/spring-context/src/test/resources/org/springframework/context/annotation/runtimehints/META-INF/spring.factories b/spring-context/src/test/resources/org/springframework/context/annotation/runtimehints/META-INF/spring.factories deleted file mode 100644 index fc129cfb4a7..00000000000 --- a/spring-context/src/test/resources/org/springframework/context/annotation/runtimehints/META-INF/spring.factories +++ /dev/null @@ -1 +0,0 @@ -org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.context.generator.RuntimeHintsPostProcessorTests.SampleRuntimeHintsRegistrar \ No newline at end of file diff --git a/spring-context/src/test/resources/org/springframework/context/generator/runtimehints/test.factories b/spring-context/src/test/resources/org/springframework/context/generator/runtimehints/test.factories new file mode 100644 index 00000000000..b39e551213e --- /dev/null +++ b/spring-context/src/test/resources/org/springframework/context/generator/runtimehints/test.factories @@ -0,0 +1,2 @@ +org.springframework.aot.hint.RuntimeHintsRegistrar= \ +org.springframework.context.generator.RuntimeHintsPostProcessorTests.SampleRuntimeHintsRegistrar \ No newline at end of file