这是我的固执方法:
Mockito.when(restTemplateMock.postForEntity(anyString(), any(), eq(String.class))).thenReturn(new ResponseEntity<String>(HttpStatus.OK));
如何抓住发送给此方法的参数?以上postForEntity
方法有3个参数。
final ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<Object> arg2Captor = ArgumentCaptor.forClass(Object.class);
final ArgumentCaptor<Class<?>> arg3Captor = ArgumentCaptor.forClass(Class.class);
Mockito.verify(restTemplateMock).postForEntity(arg1Captor, arg2Captor, arg3Captor);
Assert.assertEquals("Whatever", arg1Captor.getValue());