Add className variants in ReflectionHintsPredicates
This commit adds predicates variants that accept `String className` instead of actual `Class<?>` when checking for fields and method hints. This is useful when the type under test is not visible from the current test class. Closes gh-29143
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.aot.hint.TypeReference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReflectionHintsPredicates}
|
||||
@@ -319,6 +320,12 @@ class ReflectionHintsPredicatesTests {
|
||||
assertPredicateMatches(reflection.onMethod(SampleClass.class, "publicMethod").introspect());
|
||||
}
|
||||
|
||||
@Test
|
||||
void methodIntrospectionFailsForUnknownType() {
|
||||
assertThatThrownBy(() -> reflection.onMethod("com.example.DoesNotExist", "publicMethod").introspect())
|
||||
.isInstanceOf(ClassNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void methodIntrospectionMatchesIntrospectPublicMethods() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
@@ -472,6 +479,12 @@ class ReflectionHintsPredicatesTests {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> reflection.onField(SampleClass.class, "missingField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailForUnknownClass() {
|
||||
assertThatThrownBy(() -> reflection.onField("com.example.DoesNotExist", "missingField"))
|
||||
.isInstanceOf(ClassNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldReflectionMatchesFieldHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.withField("publicField"));
|
||||
|
||||
Reference in New Issue
Block a user