@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2023 the original author or authors .
* Copyright 2002 - 2024 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
*
*
* @author Brian Clozel
* @author Brian Clozel
* /
* /
@SuppressWarnings ( "removal" )
class ReflectionHintsPredicatesTests {
class ReflectionHintsPredicatesTests {
private static Constructor < ? > privateConstructor ;
private static Constructor < ? > privateConstructor ;
@ -160,6 +161,12 @@ class ReflectionHintsPredicatesTests {
assertPredicateDoesNotMatch ( reflection . onConstructor ( publicConstructor ) . introspect ( ) ) ;
assertPredicateDoesNotMatch ( reflection . onConstructor ( publicConstructor ) . introspect ( ) ) ;
}
}
@Test
void constructorIntrospectionMatchesTypeHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class ) ;
assertPredicateMatches ( reflection . onConstructor ( publicConstructor ) . introspect ( ) ) ;
}
@Test
@Test
void constructorIntrospectionMatchesConstructorHint ( ) {
void constructorIntrospectionMatchesConstructorHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
@ -230,22 +237,16 @@ class ReflectionHintsPredicatesTests {
}
}
@Test
@Test
void privateConstructorIntrospectionMatchesConstructorHint ( ) {
void privateConstructorIntrospectionMatchesTypeHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
runtimeHints . reflection ( ) . registerType ( SampleClass . class ) ;
typeHint . withConstructor ( TypeReference . listOf ( String . class ) , ExecutableMode . INTROSPECT ) ) ;
assertPredicateMatches ( reflection . onConstructor ( privateConstructor ) . introspect ( ) ) ;
assertPredicateMatches ( reflection . onConstructor ( privateConstructor ) . introspect ( ) ) ;
}
}
@Test
@Test
void privateConstructorIntrospectionDoesNotMatchIntrospectPublicConstructors ( ) {
void privateConstructorIntrospectionMatchesConstructorHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . INTROSPECT_PUBLIC_CONSTRUCTORS ) ;
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
assertPredicateDoesNotMatch ( reflection . onConstructor ( privateConstructor ) . introspect ( ) ) ;
typeHint . withConstructor ( TypeReference . listOf ( String . class ) , ExecutableMode . INTROSPECT ) ) ;
}
assertPredicateMatches ( reflection . onConstructor ( privateConstructor ) . introspect ( ) ) ;
@Test
void privateConstructorIntrospectionDoesNotMatchInvokePublicConstructors ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . INVOKE_PUBLIC_CONSTRUCTORS ) ;
assertPredicateDoesNotMatch ( reflection . onConstructor ( privateConstructor ) . introspect ( ) ) ;
}
}
@Test
@Test
@ -303,6 +304,12 @@ class ReflectionHintsPredicatesTests {
@Nested
@Nested
class ReflectionOnMethod {
class ReflectionOnMethod {
@Test
void methodIntrospectionMatchesTypeHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class ) ;
assertPredicateMatches ( reflection . onMethod ( SampleClass . class , "publicMethod" ) . introspect ( ) ) ;
}
@Test
@Test
void methodIntrospectionMatchesMethodHint ( ) {
void methodIntrospectionMatchesMethodHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
@ -328,18 +335,6 @@ class ReflectionHintsPredicatesTests {
assertPredicateMatches ( reflection . onMethod ( SampleClass . class , "publicMethod" ) . introspect ( ) ) ;
assertPredicateMatches ( reflection . onMethod ( SampleClass . class , "publicMethod" ) . introspect ( ) ) ;
}
}
@Test
void methodIntrospectionDoesNotMatchIntrospectDeclaredMethods ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . INTROSPECT_DECLARED_METHODS ) ;
assertPredicateDoesNotMatch ( reflection . onMethod ( SampleClass . class , "publicMethod" ) . introspect ( ) ) ;
}
@Test
void methodIntrospectionDoesNotMatchInvokeDeclaredMethods ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . INVOKE_DECLARED_METHODS ) ;
assertPredicateDoesNotMatch ( reflection . onMethod ( SampleClass . class , "publicMethod" ) . introspect ( ) ) ;
}
@Test
@Test
void methodInvocationDoesNotMatchMethodHint ( ) {
void methodInvocationDoesNotMatchMethodHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
@ -379,22 +374,16 @@ class ReflectionHintsPredicatesTests {
}
}
@Test
@Test
void privateMethodIntrospectionMatchesMethodHint ( ) {
void privateMethodIntrospectionMatchesTypeHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
runtimeHints . reflection ( ) . registerType ( SampleClass . class ) ;
typeHint . withMethod ( "privateMethod" , Collections . emptyList ( ) , ExecutableMode . INTROSPECT ) ) ;
assertPredicateMatches ( reflection . onMethod ( SampleClass . class , "privateMethod" ) . introspect ( ) ) ;
assertPredicateMatches ( reflection . onMethod ( SampleClass . class , "privateMethod" ) . introspect ( ) ) ;
}
}
@Test
@Test
void privateMethodIntrospectionDoesNotMatchIntrospectPublicMethods ( ) {
void privateMethodIntrospectionMatchesMethodHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - >
assertPredicateDoesNotMatch ( reflection . onMethod ( SampleClass . class , "privateMethod" ) . introspect ( ) ) ;
typeHint . withMethod ( "privateMethod" , Collections . emptyList ( ) , ExecutableMode . INTROSPECT ) ) ;
}
assertPredicateMatches ( reflection . onMethod ( SampleClass . class , "privateMethod" ) . introspect ( ) ) ;
@Test
void privateMethodIntrospectionDoesNotMatchInvokePublicMethods ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . INVOKE_PUBLIC_METHODS ) ;
assertPredicateDoesNotMatch ( reflection . onMethod ( SampleClass . class , "privateMethod" ) . introspect ( ) ) ;
}
}
@Test
@Test
@ -464,15 +453,15 @@ class ReflectionHintsPredicatesTests {
}
}
@Test
@Test
void fieldReflectionMatchesField Hint ( ) {
void fieldReflectionMatchesType Hint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - > typeHint . withField ( "publicField" ) ) ;
runtimeHints . reflection ( ) . registerType ( SampleClass . class ) ;
assertPredicateMatches ( reflection . onField ( SampleClass . class , "publicField" ) ) ;
assertPredicateMatches ( reflection . onField ( SampleClass . class , "publicField" ) ) ;
}
}
@Test
@Test
void fieldReflectionDoesNot MatchNonR egi stered Field dHint ( ) {
void fieldReflectionMatchesFieldHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - > typeHint . withField ( "publicField" ) ) ;
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - > typeHint . withField ( "publicField" ) ) ;
assertPredicateDoesNot Match ( reflection . onField ( SampleClass . class , "private Field" ) ) ;
assertPredicateMatches ( reflection . onField ( SampleClass . class , "public Field" ) ) ;
}
}
@Test
@Test
@ -482,21 +471,27 @@ class ReflectionHintsPredicatesTests {
}
}
@Test
@Test
void fieldReflectionDoesNotMatchDeclared FieldsHint ( ) {
void fieldInvocationMatchesPublic FieldsHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . DECLARED _FIELDS) ;
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . INVOKE_PUBLIC _FIELDS) ;
assertPredicateDoesNot Match ( reflection . onField ( SampleClass . class , "publicField" ) ) ;
assertPredicateMatches ( reflection . onField ( SampleClass . class , "publicField" ) . invocation ( ) ) ;
}
}
@Test
@Test
void privateFieldReflectionMatchesFieldHint ( ) {
void fieldInvocationDoesNotMatchTypeHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - > typeHint . withField ( "privateField" ) ) ;
runtimeHints . reflection ( ) . registerType ( SampleClass . class ) ;
assertPredicateDoesNotMatch ( reflection . onField ( SampleClass . class , "publicField" ) . invocation ( ) ) ;
}
@Test
void privateFieldReflectionMatchesTypeHint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class ) ;
assertPredicateMatches ( reflection . onField ( SampleClass . class , "privateField" ) ) ;
assertPredicateMatches ( reflection . onField ( SampleClass . class , "privateField" ) ) ;
}
}
@Test
@Test
void privateFieldReflectionDoesNotMatchPublicFieldsHint ( ) {
void privateFieldReflectionMatchesField Hint ( ) {
runtimeHints . reflection ( ) . registerType ( SampleClass . class , MemberCategory . PUBLIC_FIELDS ) ;
runtimeHints . reflection ( ) . registerType ( SampleClass . class , typeHint - > typeHint . withField ( "privateField" ) ) ;
assertPredicateDoesNot Match ( reflection . onField ( SampleClass . class , "privateField" ) ) ;
assertPredicateMatches ( reflection . onField ( SampleClass . class , "privateField" ) ) ;
}
}
@Test
@Test
@ -505,6 +500,18 @@ class ReflectionHintsPredicatesTests {
assertPredicateMatches ( reflection . onField ( SampleClass . class , "privateField" ) ) ;
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 ( ) ) ;
}
}
}
private void assertPredicateMatches ( Predicate < RuntimeHints > predicate ) {
private void assertPredicateMatches ( Predicate < RuntimeHints > predicate ) {