Fix hints and predicates for Field reflective access
This commit revisits the arrangement for Field hints after changes made in gh-34239. Closes gh-34294
This commit is contained in:
@@ -54,7 +54,7 @@ class BindingReflectionHintsRegistrarTests {
|
||||
.satisfies(typeHint -> {
|
||||
assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleEmptyClass.class));
|
||||
assertThat(typeHint.getMemberCategories()).containsExactlyInAnyOrder(
|
||||
MemberCategory.INVOKE_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
MemberCategory.ACCESS_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
assertThat(typeHint.constructors()).isEmpty();
|
||||
assertThat(typeHint.fields()).isEmpty();
|
||||
assertThat(typeHint.methods()).isEmpty();
|
||||
@@ -68,7 +68,7 @@ class BindingReflectionHintsRegistrarTests {
|
||||
typeHint -> {
|
||||
assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleEmptyClass.class));
|
||||
assertThat(typeHint.getMemberCategories()).containsExactlyInAnyOrder(
|
||||
MemberCategory.INVOKE_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
MemberCategory.ACCESS_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
assertThat(typeHint.constructors()).isEmpty();
|
||||
assertThat(typeHint.fields()).isEmpty();
|
||||
assertThat(typeHint.methods()).isEmpty();
|
||||
@@ -76,7 +76,7 @@ class BindingReflectionHintsRegistrarTests {
|
||||
typeHint -> {
|
||||
assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleExtendingClass.class));
|
||||
assertThat(typeHint.getMemberCategories()).containsExactlyInAnyOrder(
|
||||
MemberCategory.INVOKE_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
MemberCategory.ACCESS_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
assertThat(typeHint.constructors()).isEmpty();
|
||||
assertThat(typeHint.fields()).isEmpty();
|
||||
assertThat(typeHint.methods()).isEmpty();
|
||||
@@ -198,7 +198,7 @@ class BindingReflectionHintsRegistrarTests {
|
||||
typeHint -> {
|
||||
assertThat(typeHint.getType()).isEqualTo(TypeReference.of(ResolvableType.class));
|
||||
assertThat(typeHint.getMemberCategories()).containsExactlyInAnyOrder(
|
||||
MemberCategory.INVOKE_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
MemberCategory.ACCESS_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
assertThat(typeHint.constructors()).isEmpty();
|
||||
assertThat(typeHint.fields()).isEmpty();
|
||||
assertThat(typeHint.methods()).hasSizeGreaterThan(1);
|
||||
@@ -267,7 +267,7 @@ class BindingReflectionHintsRegistrarTests {
|
||||
@Test
|
||||
void registerTypeForJacksonAnnotations() {
|
||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithJsonProperty.class);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onFieldInvocation(SampleClassWithJsonProperty.class, "privateField"))
|
||||
assertThat(RuntimeHintsPredicates.reflection().onFieldAccess(SampleClassWithJsonProperty.class, "privateField"))
|
||||
.accepts(this.hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleClassWithJsonProperty.class, "packagePrivateMethod"))
|
||||
.accepts(this.hints);
|
||||
@@ -276,7 +276,7 @@ class BindingReflectionHintsRegistrarTests {
|
||||
@Test
|
||||
void registerTypeForInheritedJacksonAnnotations() {
|
||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithInheritedJsonProperty.class);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onFieldInvocation(SampleClassWithJsonProperty.class, "privateField"))
|
||||
assertThat(RuntimeHintsPredicates.reflection().onFieldAccess(SampleClassWithJsonProperty.class, "privateField"))
|
||||
.accepts(this.hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleClassWithJsonProperty.class, "packagePrivateMethod"))
|
||||
.accepts(this.hints);
|
||||
|
||||
@@ -381,68 +381,56 @@ class ReflectionHintsPredicatesTests {
|
||||
|
||||
@Test
|
||||
void shouldFailForUnknownClass() {
|
||||
assertThatThrownBy(() -> reflection.onFieldInvocation("com.example.DoesNotExist", "missingField"))
|
||||
assertThatThrownBy(() -> reflection.onFieldAccess("com.example.DoesNotExist", "missingField"))
|
||||
.isInstanceOf(ClassNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldReflectionMatchesTypeHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "publicField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldReflectionMatchesFieldHint() {
|
||||
void publicFieldAccessMatchesFieldHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.withField("publicField"));
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "publicField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldReflectionMatchesPublicFieldsHint() {
|
||||
void publicFieldAccessMatchesPublicFieldsHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.PUBLIC_FIELDS);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "publicField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldInvocationMatchesPublicFieldsHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_PUBLIC_FIELDS);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "publicField").invocation());
|
||||
void publicFieldAccessMatchesAccessPublicFieldsHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.ACCESS_PUBLIC_FIELDS);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "publicField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldInvocationDoesNotMatchTypeHint() {
|
||||
void fieldAccessDoesNotMatchTypeHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class);
|
||||
assertPredicateDoesNotMatch(reflection.onField(SampleClass.class, "publicField").invocation());
|
||||
assertPredicateDoesNotMatch(reflection.onField(SampleClass.class, "publicField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateFieldReflectionMatchesTypeHint() {
|
||||
void privateFieldAccessDoesNotMatchTypeHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "privateField"));
|
||||
assertPredicateDoesNotMatch(reflection.onField(SampleClass.class, "privateField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateFieldReflectionMatchesFieldHint() {
|
||||
void privateFieldAccessMatchesFieldHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.withField("privateField"));
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "privateField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateFieldReflectionMatchesDeclaredFieldsHint() {
|
||||
void privateFieldAccessMatchesDeclaredFieldsHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.DECLARED_FIELDS);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "privateField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateFieldInvocationMatchesDeclaredFieldsHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_FIELDS);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "privateField").invocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateFieldInvocationDoesNotMatchTypeHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class);
|
||||
assertPredicateDoesNotMatch(reflection.onField(SampleClass.class, "privateField").invocation());
|
||||
void privateFieldAccessMatchesAccessDeclaredFieldsHint() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.ACCESS_DECLARED_FIELDS);
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "privateField"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class FileNativeConfigurationWriterTests {
|
||||
ReflectionHints reflectionHints = hints.reflection();
|
||||
reflectionHints.registerType(StringDecoder.class, builder -> builder
|
||||
.onReachableType(String.class)
|
||||
.withMembers(MemberCategory.INVOKE_PUBLIC_FIELDS, MemberCategory.INVOKE_DECLARED_FIELDS,
|
||||
.withMembers(MemberCategory.ACCESS_PUBLIC_FIELDS, MemberCategory.ACCESS_DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS)
|
||||
.withField("DEFAULT_CHARSET")
|
||||
|
||||
@@ -82,7 +82,7 @@ class RuntimeHintsWriterTests {
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
hints.reflection().registerType(StringDecoder.class, builder -> builder
|
||||
.onReachableType(String.class)
|
||||
.withMembers(MemberCategory.INVOKE_PUBLIC_FIELDS, MemberCategory.INVOKE_DECLARED_FIELDS,
|
||||
.withMembers(MemberCategory.ACCESS_PUBLIC_FIELDS, MemberCategory.ACCESS_DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS,
|
||||
MemberCategory.UNSAFE_ALLOCATED)
|
||||
|
||||
Reference in New Issue
Block a user