I can unit test most of my Spring classes without needing to do Spring "stuff".
I can unit test @Before advice methods without using Spring too:
Example code:
@Before("execution(* run(..)) && " + "" +
"target(target) && " +
"args(name)")
public void logName(Object target, String name) {
logger.info("{} - run: {}", target, name);
}
Example test:
@Test
public void testLogName() {
aspect.setLogger(mockLogger);
aspect.logName(this,"Barry");
assertTrue(mockLogger.hasLogged("TestAspect - run: Barry"));
}
However @Around advice deals with a ProceedingJoinPoint object:
@Around("com.xyz.myapp.SystemArchitecture.businessService()")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
// start stopwatch
Object retVal = pjp.proceed();
// stop stopwatch
return retVal;
}
I don't know how to instantiate a ProceedingJoinPoint object. How do I test this class without starting a whole Spring application context?
question from:
https://stackoverflow.com/questions/11436600/unit-testing-spring-around-aop-methods 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…