powermockito “mock public 方法内部 Private方法的问题”

 

我需要测试的方法是 public 方法:

public ResponseResult subscribe(SysSubscription sysSubscription) throws JsonGenerationException, JsonMappingException, IOException {
LOGGER.debug("=====================subscribe Subscription=======================");
ResponseResult result = new ResponseResult();

if (checkNotNull(sysSubscription)) {
return handleSubscribe(sysSubscription, result);
}
return result;
}

 

但是在handleSubscribe内部会调用 private 方法: 

private ResponseResult createResponseResultByResponse(Response response, ResponseResult responseResult) {

 

试了 powermockito spy 来 partially mock private 方法发现没用。 因为这是两层的public 方法。

 

只好把方法改成

protected ResponseResult createResponseResultByResponse(Response response, ResponseResult responseResult) {

I'm falling off the sky all alone.The courage inside is gonna break the fall. Nothing can dim my light within. I am That I am 程序 = 数据结构 + 算法
posted @ 2015-12-23 17:37  IamThat  阅读(1800)  评论(0编辑  收藏  举报