Polish "Add hints to instantiate HttpService group adapters"

See gh-35038
This commit is contained in:
Stéphane Nicoll
2025-06-12 21:24:58 +02:00
parent 8142f80581
commit 8bf9e0cbff
7 changed files with 45 additions and 131 deletions
@@ -16,43 +16,32 @@
package org.springframework.web.client.support;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.beans.factory.aot.AotServices;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link RestClientHttpServiceGroupAdapterRuntimeHints}.
* Tests for {@link RestClientHttpServiceGroupAdapter}.
*
* @author Olga Maciaszek-Sharma
* @author Stephane Nicoll
*/
class RestClientHttpServiceGroupAdapterRuntimeHintsRegistrarTests {
private RuntimeHints hints;
@BeforeEach
void setUp() {
this.hints = new RuntimeHints();
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
.load(RuntimeHintsRegistrar.class)
.forEach(registrar ->
registrar.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
}
class RestClientHttpServiceGroupAdapterTests {
@Test
void shouldRegisterHintsForAdapter() {
void registerInstantiationHints() throws Exception {
RuntimeHints hints = new RuntimeHints();
AotServices.factories().load(RuntimeHintsRegistrar.class)
.forEach(registrar -> registrar.registerHints(hints,
ClassUtils.getDefaultClassLoader()));
assertThat(RuntimeHintsPredicates.reflection()
.onType(RestClientHttpServiceGroupAdapter.class)
.withMemberCategory(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
.accepts(this.hints);
.onConstructorInvocation(RestClientHttpServiceGroupAdapter.class.getConstructor())).accepts(hints);
}
}