The problem is that I am not able to mock this aspectj class while running the unit test because somehow it is injected in context before I mock it.
Example Code -
@Aspect
public class ExampleAspect {
@Around ("execution * com.*.*.*(..)")
public void printResult(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Before Method Execution");
joinPoint.proceed();
System.out.println("After Method Execution");
} }
Test class -
public class ClassATest
{
@Mock
private ExampleAspect mockExampleAspect;
private ClassA testClass;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
Mockito.doNothing().when(mockExampleAspect).printResult(anyList());
testClass = new ClassA();
}
@Test
public void test() {
// before and after methodA() is executed it is intercepted by the bean of ExampleAspect
testClass.methodA();
}
}
I am able to use this aspect successfully. The problem is with the unit test case. How can i mock this aspectj class or disable aspectj for unit testcase? Thanks