我正在尝试模拟从另一个方法调用的方法,而不使用类对象。在指定的代码中,我想在不使用对象的情况下模拟调用 methodB() 的 methodA()。
我无法更改现有课程中的任何内容。
class A{
public String methodA(){
//do something
String s = methodB(employee);
}
public String methodB(Employee e){
e.getId();
}
}
我已经尝试过:
答案 0 :(得分:0)
A a = mock(A.class);
when(a.methodA()).thenReturn("Whatever you want");