我有一个处理程序类,负责创建用户 User user = UserUtil.create(dbs, dba, jo, user);
我使用下面的代码来模拟静态方法,但它总是返回 null
.
@PrepareForTest({ UserHandler.class,UserUtil.class,ModelUtil.class,User.class })
@Test
public void testCreate() {
try {
DBSession dbSession = mock(DBSession.class);
DBAdmin admin = mock(DBAdmin.class);
//private static method execution
PowerMockito.mockStatic(UserUtil.class);
PowerMockito.doReturn(userList).when(UserUtil.class,"getUserWithEmailid",new DBSession("testOrg"),admin, request.getParamJo(), jsonString);
PowerMockito.doNothing().when(UserUtil.class,"validateRoleLeval",new DBSession("testOrg"),9990);
//public static method execution
PowerMockito.spy(UserUtil.class);
PowerMockito.doReturn(jsonString).when(UserUtil.class,"create",dbSession,admin, request.getParamJo(), jsonString);
UserHandler handler = new UserHandler();
ZResponse response = handler.create(request);
我不知道上面的代码有什么问题。
暂无答案!
目前还没有任何答案,快来回答吧!