@ -61,32 +61,26 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetClassesShouldNotMatchReflectionOnType ( ) {
void classForNameShouldNotMatchWhenMissingReflectionOnType ( ) {
hints . reflection ( ) . registerType ( String . class ) ;
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_FORNAME )
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETCLASSES , this . stringGetClasses ) ;
. withArgument ( "java.lang.String" ) . returnValue ( String . class ) . build ( ) ;
}
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_FORNAME , invocation ) ;
@Test
void classGetClassesShouldMatchPublicClasses ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . PUBLIC_CLASSES ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCLASSES , this . stringGetClasses ) ;
}
}
@Test
@Test
void classGetClassesShouldMatchDeclaredClasses ( ) {
void classGetClassesShouldMatchReflectionOnType ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . DECLARED_CLASSES ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCLASSES , this . stringGetClasses ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCLASSES , this . stringGetClasses ) ;
}
}
@Test
@Test
void classGetDeclaredClassesShouldMatchDeclaredClassesHint ( ) {
void classGetDeclaredClassesShouldMatchReflectionOnType ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . DECLARED_CLASSES ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCLASSES , this . stringGetDeclaredClasses ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCLASSES , this . stringGetDeclaredClasses ) ;
}
}
@Test
@Test
void classGetDeclaredClassesShouldNotMatchPublicClassesHint ( ) {
void classGetDeclaredClassesShouldNotMatchWhenMissingReflectionOnType ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . PUBLIC_CLASSES ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDCLASSES , this . stringGetDeclaredClasses ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDCLASSES , this . stringGetDeclaredClasses ) ;
}
}
@ -124,20 +118,19 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetConstructorShouldMatchIntrospectPublicConstructors Hint ( ) {
void classGetConstructorShouldMatchType Hint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_CONSTRUCTORS ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
}
}
@Test
@Test
void classGetConstructorShouldMatchInvokePublicConstructorsHint ( ) {
void classGetConstructorShouldNotMatchWhenMissingTypeHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INVOKE_PUBLIC_CONSTRUCTORS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
}
}
@Test
@Test
void classGetConstructorShouldMatchIntrospectDeclared ConstructorsHint ( ) {
void classGetConstructorShouldMatchInvokePublic ConstructorsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED _CONSTRUCTORS ) ;
hints . reflection ( ) . registerType ( String . class , MemberCategory . INVOKE_PUBLIC _CONSTRUCTORS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
}
}
@ -147,13 +140,6 @@ class InstrumentedMethodTests {
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
}
}
@Test
void classGetConstructorShouldMatchIntrospectConstructorHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - >
typeHint . withConstructor ( Collections . emptyList ( ) , ExecutableMode . INTROSPECT ) ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTOR , this . stringGetConstructor ) ;
}
@Test
@Test
void classGetConstructorShouldMatchInvokeConstructorHint ( ) {
void classGetConstructorShouldMatchInvokeConstructorHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - >
hints . reflection ( ) . registerType ( String . class , typeHint - >
@ -162,20 +148,19 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetConstructorsShouldMatchIntrospectPublicConstructors Hint ( ) {
void classGetConstructorsShouldMatchType Hint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_CONSTRUCTORS ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
}
}
@Test
@Test
void classGetConstructorsShouldMatchInvokePublicConstructorsHint ( ) {
void classGetConstructorsShouldNotMatchWhemMissingTypeHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INVOKE_PUBLIC_CONSTRUCTORS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
}
}
@Test
@Test
void classGetConstructorsShouldMatchIntrospectDeclared ConstructorsHint ( ) {
void classGetConstructorsShouldMatchInvokePublic ConstructorsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED _CONSTRUCTORS ) ;
hints . reflection ( ) . registerType ( String . class , MemberCategory . INVOKE_PUBLIC _CONSTRUCTORS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
}
}
@ -186,36 +171,16 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetConstructors ShouldNot MatchTypeReflection Hint ( ) {
void classGetDeclared ConstructorShouldMatchTypeHint ( ) {
hints . reflection ( ) . registerType ( String . class ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
}
@Test
void classGetConstructorsShouldNotMatchConstructorReflectionHint ( ) throws Exception {
hints . reflection ( ) . registerConstructor ( String . class . getConstructor ( ) , ExecutableMode . INVOKE ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETCONSTRUCTORS , this . stringGetConstructors ) ;
}
@Test
void classGetDeclaredConstructorShouldMatchIntrospectDeclaredConstructorsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED_CONSTRUCTORS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTOR , this . stringGetDeclaredConstructor ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTOR , this . stringGetDeclaredConstructor ) ;
}
}
@Test
@Test
void classGetDeclaredConstructorShouldNotMatchIntrospectPublicConstructorsHint ( ) {
void classGetDeclaredConstructorShouldNotMatchWhenMissingTypeHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_CONSTRUCTORS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTOR , this . stringGetDeclaredConstructor ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTOR , this . stringGetDeclaredConstructor ) ;
}
}
@Test
void classGetDeclaredConstructorShouldMatchIntrospectConstructorHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - >
typeHint . withConstructor ( TypeReference . listOf ( byte [ ] . class , byte . class ) , ExecutableMode . INTROSPECT ) ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTOR , this . stringGetDeclaredConstructor ) ;
}
@Test
@Test
void classGetDeclaredConstructorShouldMatchInvokeConstructorHint ( ) {
void classGetDeclaredConstructorShouldMatchInvokeConstructorHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - >
hints . reflection ( ) . registerType ( String . class , typeHint - >
@ -223,12 +188,6 @@ class InstrumentedMethodTests {
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTOR , this . stringGetDeclaredConstructor ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTOR , this . stringGetDeclaredConstructor ) ;
}
}
@Test
void classGetDeclaredConstructorsShouldMatchIntrospectDeclaredConstructorsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED_CONSTRUCTORS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTORS , this . stringGetDeclaredConstructors ) ;
}
@Test
@Test
void classGetDeclaredConstructorsShouldMatchInvokeDeclaredConstructorsHint ( ) {
void classGetDeclaredConstructorsShouldMatchInvokeDeclaredConstructorsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INVOKE_DECLARED_CONSTRUCTORS ) ;
hints . reflection ( ) . registerType ( String . class , MemberCategory . INVOKE_DECLARED_CONSTRUCTORS ) ;
@ -236,20 +195,13 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetDeclaredConstructorsShouldNotMatchIntrospectPublicConstructorsHint ( ) {
void classGetDeclaredConstructorsShouldMatchTypeReflectionHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_CONSTRUCTORS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTORS , this . stringGetDeclaredConstructors ) ;
}
@Test
void classGetDeclaredConstructorsShouldNotMatchTypeReflectionHint ( ) {
hints . reflection ( ) . registerType ( String . class ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationDoesNot Match ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTORS , this . stringGetDeclaredConstructors ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTORS , this . stringGetDeclaredConstructors ) ;
}
}
@Test
@Test
void classGetDeclaredConstructorsShouldNotMatchConstructorReflectionHint ( ) throws Exception {
void classGetDeclaredConstructorsShouldNotMatchWhenMissingTypeReflectionHint ( ) {
hints . reflection ( ) . registerConstructor ( String . class . getConstructor ( ) , ExecutableMode . INVOKE ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTORS , this . stringGetDeclaredConstructors ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDCONSTRUCTORS , this . stringGetDeclaredConstructors ) ;
}
}
@ -262,15 +214,6 @@ class InstrumentedMethodTests {
assertThatInvocationMatches ( InstrumentedMethod . CONSTRUCTOR_NEWINSTANCE , invocation ) ;
assertThatInvocationMatches ( InstrumentedMethod . CONSTRUCTOR_NEWINSTANCE , invocation ) ;
}
}
@Test
void constructorNewInstanceShouldNotMatchIntrospectHintOnConstructor ( ) throws NoSuchMethodException {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CONSTRUCTOR_NEWINSTANCE )
. onInstance ( String . class . getConstructor ( ) ) . returnValue ( "" ) . build ( ) ;
hints . reflection ( ) . registerType ( String . class , typeHint - >
typeHint . withConstructor ( Collections . emptyList ( ) , ExecutableMode . INTROSPECT ) ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CONSTRUCTOR_NEWINSTANCE , invocation ) ;
}
}
}
@Nested
@Nested
@ -295,22 +238,8 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetDeclaredMethodShouldMatchIntrospectDeclaredMethodsHint ( ) {
void classGetDeclaredMethodShouldMatchTypeReflectionHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED_METHODS ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDMETHOD , this . stringGetScaleMethod ) ;
}
@Test
void classGetDeclaredMethodShouldNotMatchIntrospectPublicMethodsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDMETHOD , this . stringGetScaleMethod ) ;
}
@Test
void classGetDeclaredMethodShouldMatchIntrospectMethodHint ( ) {
List < TypeReference > parameterTypes = TypeReference . listOf ( int . class , float . class ) ;
hints . reflection ( ) . registerType ( String . class , typeHint - >
typeHint . withMethod ( "scale" , parameterTypes , ExecutableMode . INTROSPECT ) ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDMETHOD , this . stringGetScaleMethod ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDMETHOD , this . stringGetScaleMethod ) ;
}
}
@ -322,12 +251,6 @@ class InstrumentedMethodTests {
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDMETHOD , this . stringGetScaleMethod ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDMETHOD , this . stringGetScaleMethod ) ;
}
}
@Test
void classGetDeclaredMethodsShouldMatchIntrospectDeclaredMethodsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED_METHODS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDMETHODS , this . stringGetScaleMethod ) ;
}
@Test
@Test
void classGetDeclaredMethodsShouldMatchInvokeDeclaredMethodsHint ( ) {
void classGetDeclaredMethodsShouldMatchInvokeDeclaredMethodsHint ( ) {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETDECLAREDMETHODS ) . onInstance ( String . class ) . build ( ) ;
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETDECLAREDMETHODS ) . onInstance ( String . class ) . build ( ) ;
@ -336,32 +259,8 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetDeclaredMethodsShouldNotMatchIntrospectPublicMethodsHint ( ) {
void classGetMethodsShouldMatchTypeReflectionHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDMETHODS , this . stringGetScaleMethod ) ;
}
@Test
void classGetDeclaredMethodsShouldNotMatchTypeReflectionHint ( ) {
hints . reflection ( ) . registerType ( String . class ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDMETHODS , this . stringGetScaleMethod ) ;
}
@Test
void classGetDeclaredMethodsShouldNotMatchMethodReflectionHint ( ) throws Exception {
hints . reflection ( ) . registerMethod ( String . class . getMethod ( "toString" ) , ExecutableMode . INVOKE ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDMETHODS , this . stringGetScaleMethod ) ;
}
@Test
void classGetMethodsShouldMatchIntrospectDeclaredMethodsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED_METHODS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHODS , this . stringGetMethods ) ;
}
@Test
void classGetMethodsShouldMatchIntrospectPublicMethodsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHODS , this . stringGetMethods ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHODS , this . stringGetMethods ) ;
}
}
@ -379,25 +278,13 @@ class InstrumentedMethodTests {
@Test
@Test
void classGetMethodsShouldNotMatchForWrongType ( ) {
void classGetMethodsShouldNotMatchForWrongType ( ) {
hints . reflection ( ) . registerType ( Integer . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
hints . reflection ( ) . registerType ( Integer . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHODS , this . stringGetMethods ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHODS , this . stringGetMethods ) ;
}
}
@Test
@Test
void classGetMethods ShouldNot MatchType ReflectionHint ( ) {
void classGetMethodShouldMatchReflectionType Hint ( ) {
hints . reflection ( ) . registerType ( String . class ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHODS , this . stringGetMethods ) ;
}
@Test
void classGetMethodsShouldNotMatchMethodReflectionHint ( ) throws Exception {
hints . reflection ( ) . registerMethod ( String . class . getMethod ( "toString" ) , ExecutableMode . INVOKE ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHODS , this . stringGetMethods ) ;
}
@Test
void classGetMethodShouldMatchIntrospectPublicMethodsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
}
}
@ -407,25 +294,6 @@ class InstrumentedMethodTests {
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
}
}
@Test
void classGetMethodShouldNotMatchIntrospectDeclaredMethodsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED_METHODS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
}
@Test
void classGetMethodShouldNotMatchInvokeDeclaredMethodsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INVOKE_DECLARED_METHODS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
}
@Test
void classGetMethodShouldMatchIntrospectMethodHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - >
typeHint . withMethod ( "toString" , Collections . emptyList ( ) , ExecutableMode . INTROSPECT ) ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
}
@Test
@Test
void classGetMethodShouldMatchInvokeMethodHint ( ) {
void classGetMethodShouldMatchInvokeMethodHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - >
hints . reflection ( ) . registerType ( String . class , typeHint - >
@ -433,21 +301,9 @@ class InstrumentedMethodTests {
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
}
}
@Test
void classGetMethodShouldNotMatchIntrospectPublicMethodsHintWhenPrivate ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetScaleMethod ) ;
}
@Test
void classGetMethodShouldMatchIntrospectDeclaredMethodsHintWhenPrivate ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . INTROSPECT_DECLARED_METHODS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetScaleMethod ) ;
}
@Test
@Test
void classGetMethodShouldNotMatchForWrongType ( ) {
void classGetMethodShouldNotMatchForWrongType ( ) {
hints . reflection ( ) . registerType ( Integer . class , MemberCategory . INTROSPECT_PUBLIC_METHODS ) ;
hints . reflection ( ) . registerType ( Integer . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETMETHOD , this . stringGetToStringMethod ) ;
}
}
@ -461,11 +317,10 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void methodInvokeShouldNotMatchIntrospectHintOnMethod ( ) throws NoSuchMethodException {
void methodInvokeShouldNotMatchReflectionTypeHint ( ) throws NoSuchMethodException {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . METHOD_INVOKE )
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . METHOD_INVOKE )
. onInstance ( String . class . getMethod ( "toString" ) ) . withArguments ( "" , new Object [ 0 ] ) . build ( ) ;
. onInstance ( String . class . getMethod ( "toString" ) ) . withArguments ( "" , new Object [ 0 ] ) . build ( ) ;
hints . reflection ( ) . registerType ( String . class , typeHint - >
hints . reflection ( ) . registerType ( String . class ) ;
typeHint . withMethod ( "toString" , Collections . emptyList ( ) , ExecutableMode . INTROSPECT ) ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . METHOD_INVOKE , invocation ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . METHOD_INVOKE , invocation ) ;
}
}
@ -496,17 +351,11 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetDeclaredFieldShouldMatchDeclaredFields Hint ( ) {
void classGetDeclaredFieldShouldMatchTypeReflection Hint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . DECLARED_FIELDS ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDFIELD , this . stringGetDeclaredField ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDFIELD , this . stringGetDeclaredField ) ;
}
}
@Test
void classGetDeclaredFieldShouldNotMatchPublicFieldsHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - > typeHint . withMembers ( MemberCategory . PUBLIC_FIELDS ) ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDFIELD , this . stringGetDeclaredField ) ;
}
@Test
@Test
void classGetDeclaredFieldShouldMatchFieldHint ( ) {
void classGetDeclaredFieldShouldMatchFieldHint ( ) {
hints . reflection ( ) . registerType ( String . class , typeHint - > typeHint . withField ( "value" ) ) ;
hints . reflection ( ) . registerType ( String . class , typeHint - > typeHint . withField ( "value" ) ) ;
@ -514,41 +363,23 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetDeclaredFieldsShouldMatchDeclaredFieldsHint ( ) {
void classGetDeclaredFieldsShouldMatchTypeReflectionHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . DECLARED_FIELDS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDFIELDS , this . stringGetDeclaredFields ) ;
}
@Test
void classGetDeclaredFieldsShouldNotMatchPublicFieldsHint ( ) {
hints . reflection ( ) . registerType ( String . class , MemberCategory . PUBLIC_FIELDS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETDECLAREDFIELDS , this . stringGetDeclaredFields ) ;
}
@Test
void classGetDeclaredFieldsShouldNotMatchTypeHint ( ) {
hints . reflection ( ) . registerType ( String . class ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationDoesNot Match ( InstrumentedMethod . CLASS_GETDECLAREDFIELDS , this . stringGetDeclaredFields ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDFIELDS , this . stringGetDeclaredFields ) ;
}
}
@Test
@Test
void classGetDeclaredFieldsShouldNot MatchFieldHint ( ) throws Exception {
void classGetDeclaredFieldsShouldMatchFieldHint ( ) throws Exception {
hints . reflection ( ) . registerField ( String . class . getDeclaredField ( "value" ) ) ;
hints . reflection ( ) . registerField ( String . class . getDeclaredField ( "value" ) ) ;
assertThatInvocationDoesNot Match ( InstrumentedMethod . CLASS_GETDECLAREDFIELDS , this . stringGetDeclaredFields ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETDECLAREDFIELDS , this . stringGetDeclaredFields ) ;
}
}
@Test
@Test
void classGetFieldShouldMatchPublicFields Hint ( ) {
void classGetFieldShouldMatchTypeReflectionHint ( ) {
hints . reflection ( ) . registerType ( PublicField . class , MemberCategory . PUBLIC_FIELDS ) ;
hints . reflection ( ) . registerType ( PublicField . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETFIELD , this . getPublicField ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETFIELD , this . getPublicField ) ;
}
}
@Test
void classGetFieldShouldNotMatchDeclaredFieldsHint ( ) {
hints . reflection ( ) . registerType ( PublicField . class , MemberCategory . DECLARED_FIELDS ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETFIELD , this . getPublicField ) ;
}
@Test
@Test
void classGetFieldShouldMatchFieldHint ( ) {
void classGetFieldShouldMatchFieldHint ( ) {
hints . reflection ( ) . registerType ( PublicField . class , typeHint - > typeHint . withField ( "field" ) ) ;
hints . reflection ( ) . registerType ( PublicField . class , typeHint - > typeHint . withField ( "field" ) ) ;
@ -559,53 +390,30 @@ class InstrumentedMethodTests {
void classGetFieldShouldNotMatchPublicFieldsHintWhenPrivate ( ) {
void classGetFieldShouldNotMatchPublicFieldsHintWhenPrivate ( ) {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELD )
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELD )
. onInstance ( String . class ) . withArgument ( "value" ) . returnValue ( null ) . build ( ) ;
. onInstance ( String . class ) . withArgument ( "value" ) . returnValue ( null ) . build ( ) ;
hints . reflection ( ) . registerType ( String . class , MemberCategory . PUBLIC_FIELDS ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETFIELD , invocation ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETFIELD , invocation ) ;
}
}
@Test
void classGetFieldShouldMatchDeclaredFieldsHintWhenPrivate ( ) throws NoSuchFieldException {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELD )
. onInstance ( String . class ) . withArgument ( "value" ) . returnValue ( String . class . getDeclaredField ( "value" ) ) . build ( ) ;
hints . reflection ( ) . registerType ( String . class , MemberCategory . DECLARED_FIELDS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETFIELD , invocation ) ;
}
@Test
@Test
void classGetFieldShouldNotMatchForWrongType ( ) {
void classGetFieldShouldNotMatchForWrongType ( ) {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELD )
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELD )
. onInstance ( String . class ) . withArgument ( "value" ) . returnValue ( null ) . build ( ) ;
. onInstance ( String . class ) . withArgument ( "value" ) . returnValue ( null ) . build ( ) ;
hints . reflection ( ) . registerType ( Integer . class , MemberCategory . DECLARED_FIELDS ) ;
hints . reflection ( ) . registerType ( Integer . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETFIELD , invocation ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETFIELD , invocation ) ;
}
}
@Test
@Test
void classGetFieldsShouldMatchPublicFieldsHint ( ) {
void classGetFieldsShouldMatchReflectionHint ( ) {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELDS )
. onInstance ( PublicField . class ) . build ( ) ;
hints . reflection ( ) . registerType ( PublicField . class , MemberCategory . PUBLIC_FIELDS ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETFIELDS , invocation ) ;
}
@Test
void classGetFieldsShouldMatchDeclaredFieldsHint ( ) {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELDS )
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETFIELDS )
. onInstance ( PublicField . class ) . build ( ) ;
. onInstance ( PublicField . class ) . build ( ) ;
hints . reflection ( ) . registerType ( PublicField . class , MemberCategory . DECLARED_FIELDS ) ;
hints . reflection ( ) . registerType ( PublicField . class ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETFIELDS , invocation ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETFIELDS , invocation ) ;
}
}
@Test
@Test
void classGetFieldsShouldNot MatchTypeHint ( ) {
void classGetFieldsShouldMatchTypeHint ( ) {
hints . reflection ( ) . registerType ( String . class ) ;
hints . reflection ( ) . registerType ( String . class ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETFIELDS , this . stringGetFields ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETFIELDS , this . stringGetFields ) ;
}
@Test
void classGetFieldsShouldNotMatchFieldHint ( ) throws Exception {
hints . reflection ( ) . registerField ( String . class . getDeclaredField ( "value" ) ) ;
assertThatInvocationDoesNotMatch ( InstrumentedMethod . CLASS_GETFIELDS , this . stringGetFields ) ;
}
}
}
}
@ -634,7 +442,7 @@ class InstrumentedMethodTests {
void classGetResourceShouldMatchResourcePatternWhenAbsolute ( ) {
void classGetResourceShouldMatchResourcePatternWhenAbsolute ( ) {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETRESOURCE )
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETRESOURCE )
. onInstance ( InstrumentedMethodTests . class ) . withArgument ( "/some/path/resource.txt" ) . build ( ) ;
. onInstance ( InstrumentedMethodTests . class ) . withArgument ( "/some/path/resource.txt" ) . build ( ) ;
hints . resources ( ) . registerPattern ( "some/*" ) ;
hints . resources ( ) . registerPattern ( "some/** " ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETRESOURCE , invocation ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETRESOURCE , invocation ) ;
}
}
@ -655,11 +463,11 @@ class InstrumentedMethodTests {
}
}
@Test
@Test
void classGetResourceShouldNotMatchResourcePatternWhenExcluded ( ) {
void classGetResourceShouldMatchWhenGlobPattern ( ) {
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETRESOURCE )
RecordedInvocation invocation = RecordedInvocation . of ( InstrumentedMethod . CLASS_GETRESOURCE )
. onInstance ( InstrumentedMethodTests . class ) . withArgument ( "/some/path/resource.txt" ) . build ( ) ;
. onInstance ( InstrumentedMethodTests . class ) . withArgument ( "/some/path/resource.txt" ) . build ( ) ;
hints . resources ( ) . registerPattern ( resourceHint - > resourceHint . includes ( "some/*" ) . excludes ( "some/path/ *" ) ) ;
hints . resources ( ) . registerPattern ( resourceHint - > resourceHint . includes ( "some/**" ) ) ;
assertThatInvocationDoesNot Match ( InstrumentedMethod . CLASS_GETRESOURCE , invocation ) ;
assertThatInvocationMatches ( InstrumentedMethod . CLASS_GETRESOURCE , invocation ) ;
}
}
}
}