Migrate hint registration to shortcuts
Migrate code to make use of the `MemberCategory` and `FieldMode` shortcuts. See gh-29011
This commit is contained in:
@@ -55,39 +55,37 @@ class InstrumentedMethodTests {
|
||||
void classForNameShouldMatchReflectionOnType() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_FORNAME)
|
||||
.withArgument("java.lang.String").returnValue(String.class).build();
|
||||
hints.reflection().registerType(String.class, typeHint -> {
|
||||
});
|
||||
hints.reflection().registerType(String.class);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_FORNAME, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetClassesShouldNotMatchReflectionOnType() {
|
||||
hints.reflection().registerType(String.class, typeHint -> {
|
||||
});
|
||||
hints.reflection().registerType(String.class);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETCLASSES, this.stringGetClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetClassesShouldMatchPublicClasses() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.PUBLIC_CLASSES));
|
||||
hints.reflection().registerType(String.class, MemberCategory.PUBLIC_CLASSES);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCLASSES, this.stringGetClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetClassesShouldMatchDeclaredClasses() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_CLASSES));
|
||||
hints.reflection().registerType(String.class, MemberCategory.DECLARED_CLASSES);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCLASSES, this.stringGetClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredClassesShouldMatchDeclaredClassesHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_CLASSES));
|
||||
hints.reflection().registerType(String.class, MemberCategory.DECLARED_CLASSES);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDCLASSES, this.stringGetDeclaredClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredClassesShouldNotMatchPublicClassesHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.PUBLIC_CLASSES));
|
||||
hints.reflection().registerType(String.class, MemberCategory.PUBLIC_CLASSES);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETDECLAREDCLASSES, this.stringGetDeclaredClasses);
|
||||
}
|
||||
|
||||
@@ -96,8 +94,7 @@ class InstrumentedMethodTests {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASSLOADER_LOADCLASS)
|
||||
.onInstance(ClassLoader.getSystemClassLoader())
|
||||
.withArgument(PublicField.class.getCanonicalName()).returnValue(PublicField.class).build();
|
||||
hints.reflection().registerType(PublicField.class, builder -> {
|
||||
});
|
||||
hints.reflection().registerType(PublicField.class);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASSLOADER_LOADCLASS, invocation);
|
||||
}
|
||||
|
||||
@@ -127,25 +124,25 @@ class InstrumentedMethodTests {
|
||||
|
||||
@Test
|
||||
void classGetConstructorShouldMatchInstrospectPublicConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTOR, this.stringGetConstructor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetConstructorShouldMatchInvokePublicConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTOR, this.stringGetConstructor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetConstructorShouldMatchIntrospectDeclaredConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTOR, this.stringGetConstructor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetConstructorShouldMatchInvokeDeclaredConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTOR, this.stringGetConstructor);
|
||||
}
|
||||
|
||||
@@ -159,43 +156,43 @@ class InstrumentedMethodTests {
|
||||
@Test
|
||||
void classGetConstructorShouldMatchInvokeConstructorHint() {
|
||||
hints.reflection().registerType(String.class, typeHint ->
|
||||
typeHint.withConstructor(Collections.emptyList(),ExecutableMode.INVOKE));
|
||||
typeHint.withConstructor(Collections.emptyList(), ExecutableMode.INVOKE));
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTOR, this.stringGetConstructor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetConstructorsShouldMatchIntrospectPublicConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTORS, this.stringGetConstructors);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetConstructorsShouldMatchInvokePublicConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTORS, this.stringGetConstructors);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetConstructorsShouldMatchIntrospectDeclaredConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTORS, this.stringGetConstructors);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetConstructorsShouldMatchInvokeDeclaredConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETCONSTRUCTORS, this.stringGetConstructors);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredConstructorShouldMatchIntrospectDeclaredConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDCONSTRUCTOR, this.stringGetDeclaredConstructor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredConstructorShouldNotMatchIntrospectPublicConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETDECLAREDCONSTRUCTOR, this.stringGetDeclaredConstructor);
|
||||
}
|
||||
|
||||
@@ -215,19 +212,19 @@ class InstrumentedMethodTests {
|
||||
|
||||
@Test
|
||||
void classGetDeclaredConstructorsShouldMatchIntrospectDeclaredConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDCONSTRUCTORS, this.stringGetDeclaredConstructors);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredConstructorsShouldMatchInvokeDeclaredConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDCONSTRUCTORS, this.stringGetDeclaredConstructors);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredConstructorsShouldNotMatchIntrospectPublicConstructorsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETDECLAREDCONSTRUCTORS, this.stringGetDeclaredConstructors);
|
||||
}
|
||||
|
||||
@@ -271,13 +268,13 @@ class InstrumentedMethodTests {
|
||||
|
||||
@Test
|
||||
void classGetDeclaredMethodShouldMatchIntrospectDeclaredMethodsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDMETHOD, this.stringGetScaleMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredMethodShouldNotMatchIntrospectPublicMethodsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETDECLAREDMETHOD, this.stringGetScaleMethod);
|
||||
}
|
||||
|
||||
@@ -299,79 +296,79 @@ class InstrumentedMethodTests {
|
||||
|
||||
@Test
|
||||
void classGetDeclaredMethodsShouldMatchIntrospectDeclaredMethodsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDMETHODS, this.stringGetScaleMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredMethodsShouldMatchInvokeDeclaredMethodsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETDECLAREDMETHODS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDMETHODS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredMethodsShouldMatchIntrospectPublicMethodsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETDECLAREDMETHODS, this.stringGetScaleMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodsShouldMatchInstrospectDeclaredMethodsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETMETHODS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHODS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodsShouldMatchInstrospectPublicMethodsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETMETHODS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(String.class, hint -> hint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHODS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodsShouldMatchInvokeDeclaredMethodsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETMETHODS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHODS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodsShouldMatchInvokePublicMethodsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETMETHODS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(String.class, hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_PUBLIC_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHODS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodsShouldNotMatchForWrongType() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETMETHODS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(Integer.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(Integer.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETMETHODS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodShouldMatchInstrospectPublicMethodsHint() throws NoSuchMethodException {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodShouldMatchInvokePublicMethodsHint() throws NoSuchMethodException {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_PUBLIC_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodShouldMatchInstrospectDeclaredMethodsHint() throws NoSuchMethodException {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodShouldMatchInvokeDeclaredMethodsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
|
||||
}
|
||||
|
||||
@@ -391,19 +388,19 @@ class InstrumentedMethodTests {
|
||||
|
||||
@Test
|
||||
void classGetMethodShouldNotMatchInstrospectPublicMethodsHintWhenPrivate() throws Exception {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetScaleMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodShouldMatchInstrospectDeclaredMethodsHintWhenPrivate() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetScaleMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetMethodShouldNotMatchForWrongType() {
|
||||
hints.reflection().registerType(Integer.class, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.reflection().registerType(Integer.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
|
||||
}
|
||||
|
||||
@@ -445,7 +442,7 @@ class InstrumentedMethodTests {
|
||||
|
||||
@Test
|
||||
void classGetDeclaredFieldShouldMatchDeclaredFieldsHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_FIELDS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.DECLARED_FIELDS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDFIELD, this.stringGetDeclaredField);
|
||||
}
|
||||
|
||||
@@ -457,41 +454,39 @@ class InstrumentedMethodTests {
|
||||
|
||||
@Test
|
||||
void classGetDeclaredFieldShouldMatchFieldHint() {
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withField("value", builder -> {
|
||||
}));
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withField("value"));
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDFIELD, this.stringGetDeclaredField);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredFieldsShouldMatchDeclaredFieldsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETDECLAREDFIELDS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_FIELDS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.DECLARED_FIELDS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETDECLAREDFIELDS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetDeclaredFieldsShouldNotMatchPublicFieldsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETDECLAREDFIELDS).onInstance(String.class).build();
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.PUBLIC_FIELDS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.PUBLIC_FIELDS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETDECLAREDFIELDS, invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetFieldShouldMatchPublicFieldsHint() {
|
||||
hints.reflection().registerType(PublicField.class, typeHint -> typeHint.withMembers(MemberCategory.PUBLIC_FIELDS));
|
||||
hints.reflection().registerType(PublicField.class, MemberCategory.PUBLIC_FIELDS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELD, this.getPublicField);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetFieldShouldMatchDeclaredFieldsHint() {
|
||||
hints.reflection().registerType(PublicField.class, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_FIELDS));
|
||||
hints.reflection().registerType(PublicField.class, MemberCategory.DECLARED_FIELDS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELD, this.getPublicField);
|
||||
}
|
||||
|
||||
@Test
|
||||
void classGetFieldShouldMatchFieldHint() {
|
||||
hints.reflection().registerType(PublicField.class, typeHint -> typeHint.withField("field", builder -> {
|
||||
}));
|
||||
hints.reflection().registerType(PublicField.class, typeHint -> typeHint.withField("field"));
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELD, this.getPublicField);
|
||||
}
|
||||
|
||||
@@ -499,7 +494,7 @@ class InstrumentedMethodTests {
|
||||
void classGetFieldShouldNotMatchPublicFieldsHintWhenPrivate() throws NoSuchFieldException {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETFIELD)
|
||||
.onInstance(String.class).withArgument("value").returnValue(null).build();
|
||||
hints.reflection().registerType(String.class, typeHint -> typeHint.withMembers(MemberCategory.PUBLIC_FIELDS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.PUBLIC_FIELDS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETFIELD, invocation);
|
||||
}
|
||||
|
||||
@@ -507,7 +502,7 @@ class InstrumentedMethodTests {
|
||||
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, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_FIELDS));
|
||||
hints.reflection().registerType(String.class, MemberCategory.DECLARED_FIELDS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELD, invocation);
|
||||
}
|
||||
|
||||
@@ -515,7 +510,7 @@ class InstrumentedMethodTests {
|
||||
void classGetFieldShouldNotMatchForWrongType() throws Exception {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETFIELD)
|
||||
.onInstance(String.class).withArgument("value").returnValue(null).build();
|
||||
hints.reflection().registerType(Integer.class, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_FIELDS));
|
||||
hints.reflection().registerType(Integer.class, MemberCategory.DECLARED_FIELDS);
|
||||
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETFIELD, invocation);
|
||||
}
|
||||
|
||||
@@ -523,7 +518,7 @@ class InstrumentedMethodTests {
|
||||
void classGetFieldsShouldMatchPublicFieldsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETFIELDS)
|
||||
.onInstance(PublicField.class).build();
|
||||
hints.reflection().registerType(PublicField.class, typeHint -> typeHint.withMembers(MemberCategory.PUBLIC_FIELDS));
|
||||
hints.reflection().registerType(PublicField.class, MemberCategory.PUBLIC_FIELDS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELDS, invocation);
|
||||
}
|
||||
|
||||
@@ -531,7 +526,7 @@ class InstrumentedMethodTests {
|
||||
void classGetFieldsShouldMatchDeclaredFieldsHint() {
|
||||
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETFIELDS)
|
||||
.onInstance(PublicField.class).build();
|
||||
hints.reflection().registerType(PublicField.class, typeHint -> typeHint.withMembers(MemberCategory.DECLARED_FIELDS));
|
||||
hints.reflection().registerType(PublicField.class, MemberCategory.DECLARED_FIELDS);
|
||||
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELDS, invocation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user