Java 需要为JUnit测试模拟连接点
我需要为JUnit测试模拟SpringJava连接点。请参阅下面的代码Java 需要为JUnit测试模拟连接点,java,spring,testing,junit,Java,Spring,Testing,Junit,我需要为JUnit测试模拟SpringJava连接点。请参阅下面的代码 /** * Pointcut that matches all Spring beans in the application's main packages. */ @Pointcut("within(com.cybersite.repository..*)"+ " || within(com.cybersite.service..*)"+
/**
* Pointcut that matches all Spring beans in the application's main packages.
*/
@Pointcut("within(com.cybersite.repository..*)"+
" || within(com.cybersite.service..*)"+
" || within(com.cybersite.web.rest..*)")
public void applicationPackagePointcut() {
// Method is empty as this is just a Pointcut, the implementations are in the advices.
}
/**
* Retrieves the {@link Logger} associated to the given {@link JoinPoint}.
*
* @param joinPoint join point we want the logger for.
* @return {@link Logger} associated to the given {@link JoinPoint}.
*/
private Logger logger(JoinPoint joinPoint) {
return LoggerFactory.getLogger(joinPoint.getSignature().getDeclaringTypeName());
}
有人知道我将如何创建模拟连接点吗?这可能会有所帮助。
JoinPoint joinPoint = mock(JoinPoint.class);
MethodSignature signature = mock(MethodSignature.class);
String typeName = "some name";
when(joinPoint.getSignature()).thenReturn(signature);
when(joinPoint.getSignature().getDeclaringTypeName()).thenReturn(typeName);