I want to access a method in an interface in my test class method in compile time just by using a custom annotation. I dont want to implement the interface by test class. Below are the examples of interface, custom annotation and Test class.
public interface A {
default Student prepareRequest() {
return Student.builder()
.firstName("FirstNamee")
.lastName("LastNamee")
.build();
}
}
@Target(ElementType.METHOD)
@ExtendWith(MockitoExtension.class)
@Test
public @interface CustomAnnotation {
}
class SampleControllerTest {
@CustomAnnotation
void testAdd() {
//prepareRequest() should be accessible here
}
}
I learnt about @Aspect, BeanPostProcessing and junit jupiter extensions for annotation processing and these are good concepts for runtime processing but I am not getting how can we access that method at compile time just by using custom annotation. Need some guidance for this.
I tried implementing Junit ParameterResolver extension by a custom extension class by giving test method parameter and injecting them at runtime. That worked for me but I dont want to give parameters to the test method and access the prepareRequest() directly