EasyMock期望调用
EasyMock提供,可以在特定的方法来的调用的数目的特别检查。假设MathApplication使用其的任意方法,其中CalculatorService.serviceUsed()方法表示CalculatorService的用于获得所需要的操作结果之前调用CalculatorService.serviceUsed()方法,只有一次。
MathApplication应该不能够调用CalculatorService.serviceUsed()一次以上。
//add the behavior of calc service to add two numbers and serviceUsed. EasyMock.expect(calcService.add(10.0,20.0)).andReturn(30.00); calcService.serviceUsed(); //limit the method call to 1, no less and no more calls are allowed EasyMock.expectLastCall().times(1);
创建CalculatorService的界面如下。
CalculatorService.javapublic interface CalculatorService { public double add(double input1, double input2); public double subtract(double input1, double input2); public double multiply(double input1, double input2); public double divide(double input1, double input2); public void serviceUsed(); }
calcService.serviceUsed()被调用一次例子
calcService.serviceUsed()调用两次例子
无需调用calcService.serviceUsed()示例