Я просмотрел сообщения в StackOverflow.
Требуется, но не вызывается: на самом деле с этим макетом не было никаких взаимодействий.
Я сделал то, что там спросили, но мне чего-то не хватает. Не могли бы вы помочь мне, что мне не хватает?
Мой Java код:
public class AccountController {
public ResponseEntity<AccountResponse> getAccountByAccountId(
@RequestHeader("Authorization") final String accountToken,
@PathVariable("accountId") String accountId) {
return accountHandler.apply(() -> {
final AcccountResponse accountResponse = accountService
.getAccountByAccountId(accountId);
return ResponseEntity.ok().body(accountResponse);
});
}
}
Мой юнит-тест:
@InjectMocks
private AccountController accountController;
@Mock
private AccountService accountService;
@Mock
private AccountHandler accountHandler;
@Captor
private ArgumentCaptor<Supplier<ResponseEntity<AccountResponse>>> responseAccount;
private static AccountResponse accountResponse;
@Before
public void setUp() {
responseEntity = ResponseEntity.ok().body(accountResponse);
}
@Test
public void getAccountByAccountIdTest() {
when(accountHandler.apply(responseAccount.capture())).thenReturn(responseEntity);
when(accountService.getAccountByAccountId(accountId)).thenReturn(accountResponse);
ResponseEntity<AccountResponse> accountResult = accountController.getAccountByAccountId(accountToken, accountId);
assertNotNull(accountResult);
assertEquals(HttpStatus.OK, accountResult.getStatusCode());
assertSame(accountResponse, accountResult.getBody());
verify(accountHandler).apply(responseAccount.capture());
verify(accountService).getAccountByAccountId(accountId); // this fails and gives me error
}
Все отлично работает, кроме verify(acccountService).getAccountByAccountId(accountId);
Я получаю ошибку как
Wanted but not invoked:
acccountService.getAccountByAccountId(
"accountId"
);
Actually, there were zero interactions with this mock.