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; package org.springframework.context.generator;
import java.io.File; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.util.Enumeration;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -77,7 +76,7 @@ class RuntimeHintsPostProcessorTests {
@Test @Test
void shouldProcessRegistrarInSpringFactory() { void shouldProcessRegistrarInSpringFactory() {
GenericApplicationContext applicationContext = createContext(); GenericApplicationContext applicationContext = createContext();
applicationContext.setClassLoader(new TestSpringFactoriesClassLoader()); applicationContext.setClassLoader(new TestSpringFactoriesClassLoader("test.factories"));
this.generator.generateApplicationContext(applicationContext, this.generationContext); this.generator.generateApplicationContext(applicationContext, this.generationContext);
assertThatSampleRegistrarContributed(); assertThatSampleRegistrarContributed();
} }
@ -162,19 +161,21 @@ class RuntimeHintsPostProcessorTests {
} }
private static class TestSpringFactoriesClassLoader extends URLClassLoader { static class TestSpringFactoriesClassLoader extends ClassLoader {
TestSpringFactoriesClassLoader() { private final String factoriesName;
super(new URL[] {testLocation()}, RuntimeHintsPostProcessorTests.class.getClassLoader());
TestSpringFactoriesClassLoader(String factoriesName) {
super(RuntimeHintsPostProcessorTests.class.getClassLoader());
this.factoriesName = factoriesName;
} }
private static URL testLocation() { @Override
try { public Enumeration<URL> getResources(String name) throws IOException {
return new File("src/test/resources/org/springframework/context/annotation/runtimehints/").toURI().toURL(); if ("META-INF/spring.factories".equals(name)) {
} return super.getResources("org/springframework/context/generator/runtimehints/" + this.factoriesName);
catch (MalformedURLException ex) {
throw new IllegalStateException(ex);
} }
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