用于链接调用的模拟或存根
2022-08-31 11:00:12
protected int parseExpire(CacheContext ctx) throws AttributeDefineException {
Method targetMethod = ctx.getTargetMethod();
CacheEnable cacheEnable = targetMethod.getAnnotation(CacheEnable.class);
ExpireExpr cacheExpire = targetMethod.getAnnotation(ExpireExpr.class);
// check for duplicate setting
if (cacheEnable.expire() != CacheAttribute.DO_NOT_EXPIRE && cacheExpire != null) {
throw new AttributeDefineException("expire are defined both in @CacheEnable and @ExpireExpr");
}
// expire time defined in @CacheEnable or @ExpireExpr
return cacheEnable.expire() != CacheAttribute.DO_NOT_EXPIRE ? cacheEnable.expire() : parseExpireExpr(cacheExpire, ctx.getArgument());
}
这是测试的方法,
Method targetMethod = ctx.getTargetMethod();
CacheEnable cacheEnable = targetMethod.getAnnotation(CacheEnable.class);
我必须模拟三个CacheContext,Method和CacheEnable。有没有让测试用例更简单的想法?