powermock + mockito使用超过param的私有方法

时间:2015-04-24 09:44:30

标签: java mockito powermock

我想在我的名为TestBean的bean中使用两个参数模拟一个私有方法, 以下是我的计划:

Student student = mock(Student.class);
    Teacher teacher = mock(Teacher.class);
    doReturn("mockResult").when(testBean1, method(TestBean.class, "kk", Student.class, Teacher.class)).withArguments(student,teacher);

kk是方法名称,它需要两个参数:第一个是学生,第二个是老师。 我得到了错误:

java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.powermock.api.mockito.internal.expectation.DefaultPrivatelyExpectedArguments.withArguments(DefaultPrivatelyExpectedArguments.java:36)

但是当我改变我的方法时:删除第二种方法,它有效,下面是程序:

Student student = mock(Student.class);
    doReturn("mockResult").when(testBean1, method(TestBean.class, "kk", Student.class)).withArguments(student);

我想知道为什么?

0 个答案:

没有答案