This commit is contained in:
Stephane Nicoll 2022-04-14 14:50:57 +02:00
parent 95f24c0897
commit 8b97c2dc9d
3 changed files with 16 additions and 14 deletions

View File

@ -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<URL> 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);
}
}

View File

@ -1 +0,0 @@
org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.context.generator.RuntimeHintsPostProcessorTests.SampleRuntimeHintsRegistrar

View File

@ -0,0 +1,2 @@
org.springframework.aot.hint.RuntimeHintsRegistrar= \
org.springframework.context.generator.RuntimeHintsPostProcessorTests.SampleRuntimeHintsRegistrar