相关疑难解决方法(0)

用于链接呼叫的模拟或存根

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());
}
Run Code Online (Sandbox Code Playgroud)

这是测试的方法,

Method targetMethod = ctx.getTargetMethod();
CacheEnable cacheEnable = targetMethod.getAnnotation(CacheEnable.class);
Run Code Online (Sandbox Code Playgroud)

我必须模拟三个CacheContext,Method和CacheEnable.有什么想法让测试用例更简单吗?

java unit-testing mocking mockito

63
推荐指数
3
解决办法
5万
查看次数

标签 统计

java ×1

mocking ×1

mockito ×1

unit-testing ×1