I'm using Mockito (3.6.x) for my unit tests in Spring Boot (2.4.x) with JUnit 4. There are unit tests where I need to mock final classes (e.g. java.lang.reflect.Method
), and there are other unit tests where I need to mock common interfaces (e.g. org.springframework.core.env.Environment
).
I have tried many solutions but none have worked for me. I found this article where I can mock final classes, but when I add the mock-inline-maker
plugin, only unit tests that mock final classes work (classes in which I mock java.lang.reflect.Method
) and the others crash (classes in which I mock org.springframework.core.env.Environment
), and vice versa when I remove the mock-inline-maker
.
Is there a way to configure the mock-inline-maker for some classes in the test and not for others?
P.S. The only reason to mock final classes is to achieve this code block in my unit tests:
MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
Method method = signature.getMethod();
CustomAnnotation customAnnotation = method.getAnnotation(CustomAnnotation.class);
I thank you all very much.