我不确定您是否将整个方法的预期一次设置为整个方法链,但这不是它的工作原理。您必须分别设置每个方法调用的期望值。
在你的情况,作为第一个方法调用是一个静态调用,你应该使用powermock并设置期望并返回它的模拟实例。然后你应该添加第二个方法调用的期望值。我已经在下面给出了示例代码,请检查它是否适用于您的案例。
@RunWith(PowerMockRunner.class)
@PrepareForTest({SampleClass.class})
public class SimpleClassTest{
@Test
public void test(){
PowerMock.mockStatic(SampleClass.class);
SampleClass sampleClassInstance = EasyMock.createMock(SampleClass);
EasyMock.expect(SampleClass.getInstance).andReturn(sampleClassInstance);
EasyMock.expect(sampleClassInstance.getSampleMethod(/*required parameter goes here*/).andReturn(/*Otherclass instance goes here*/);
PowerMock.replayAll();
EasyMock.replay(sampleClassInstance);
}
}
当给出答案时,最好给出[关于为什么你的答案的一些解释](http://stackoverflow.com/help/how-to-answer)是一个答案。 –
感谢您的建议@StephenRauch 我已编辑我的回应:) – Sravya