这是我的简短方法:
Mockito.when(restTemplateMock.postForEntity(anyString(), any(), eq(String.class))).thenReturn(new ResponseEntity<String>(HttpStatus.OK));
如何抓住发送到此方法的参数?上面的postForEntity
方法有3个参数。
答案 0 :(得分: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());