我可以使用 Mockito thenReturn() 的 return 值作为下一个 Mockito when() 的参数吗?
Can I use the return value from Mockito thenReturn() as an argument on the next Mockito when()?
我可以这样做吗:
final var msg = Mockito.when(mapper.map(request)).thenReturn(message);
final var resp = Mockito.when(messaging.send(msg.getMock())).thenReturn(response);
我有 Mockito.any() 而不是 messaging.send() 中的 msg,如果我尝试使用 msg,我会收到 ClassCastException。
这样的事情有可能吗?
这是一个示例代码。可能不是确切的语法,因为我在手机上 phone:
ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); //or any other class your argument is
Mockito.verify(service.yourMethod(captor.capture());
Assertions.assertThat(captor.getValue()).isEqualTo(yourExpectedValue):
我可以这样做吗:
final var msg = Mockito.when(mapper.map(request)).thenReturn(message);
final var resp = Mockito.when(messaging.send(msg.getMock())).thenReturn(response);
我有 Mockito.any() 而不是 messaging.send() 中的 msg,如果我尝试使用 msg,我会收到 ClassCastException。
这样的事情有可能吗?
这是一个示例代码。可能不是确切的语法,因为我在手机上 phone:
ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); //or any other class your argument is
Mockito.verify(service.yourMethod(captor.capture());
Assertions.assertThat(captor.getValue()).isEqualTo(yourExpectedValue):