powermock中的PowerMockito.when().thenReturn()和PowerMockito.doReturn().when()有啥区别?

西夏一品堂 发布于 2017/08/21 10:27
阅读 3K+
收藏 0
interface UserMapper {
	public int insert(User user);
}

@Test
public void test1() {
	UserMapper mapper = PowerMockito.mock(UserMapper.class);
	PowerMockito.when(mapper.insert(Mockito.any(User.class))).thenReturn(1);
	System.out.println(mapper.insert(new User(1, "jack")));
}

@Test
public void test2() {
	UserMapper mapper = PowerMockito.mock(UserMapper.class);
	PowerMockito.doReturn(2).when(mapper).insert(Mockito.any(User.class));		
	System.out.println(mapper.insert(new User(1, "jack")));
}

这两种用法有什么区别?

加载中
返回顶部
顶部