如何根据参数属性在Mockito中返回不同的值?
我测试的类接收客户端包装器:
测试的类(截图)
private ClientWrapper cw
public Tested(ClientWrapper cw) {
this.cw = cw;
}
public String get(Request request) {
return cw.getClient().get(request);
}
测试初始化:
ClientWrapper cw = Mockito.mock(ClientWrapper.class);
Client client = Mockito.mock(Client.class);
Mockito.when(cw.getClient()).thenReturn(client);
//Here is where I want to alternate the return value:
Mockito.when(client.get(Mockito.any(Request.class))).thenReturn("100");
在exmaple中,我总是返回“100”,但是Request有一个属性,我想根据值返回不同的值。id
client.get(Request)
request.getId()
我该怎么做?