https://blog.51cto.com/u_15009374/3145673
@Test
public void testStudentPrivateService(){
StudentPrivateService studentPrivateService = PowerMockito.spy(new StudentPrivateService());
try {
PowerMockito.doAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
String arg= (String) invocation.getArguments()[0];
if("rongrong".equals(arg)){
return 1;
}else {
return 0;
}
} }).when(studentPrivateService,"checkExist","rongrong");
boolean exist = studentPrivateService.isExist("rongrong"); assertTrue(exist); PowerMockito.verifyPrivate(studentPrivateService).invoke("checkExist","rongrong"); } catch (Exception e) { e.printStackTrace(); } }}