Bank System,2022年1月6日
spring data jpaでページングするときのテスト
@Test
void 전체_계좌_조회() {
int page = 0;
int perPage = 5;
Pageable pageable = PageRequest.of(page, perPage);
List<Account> accountList = new ArrayList<>();
accountList.add(account);
Page<Account> accounts = new PageImpl<>(accountList);
// given
when(userService.getUser(request)).thenReturn(user);
when(accountRepository.findByUser(user, pageable)).thenReturn(accounts);
// when
accountService.getAccounts(page, perPage, request);
// then
verify(userService).getUser(request);
verify(accountRepository).findByUser(user, PageRequest.of(page, perPage));
}
springdatajpaでページングしている場合は、上記の操作を実行します.リストはNew PageImpl<>()でPageオブジェクト(?)として使用されます.作成して使えばいいです.Reference
この問題について(Bank System,2022年1月6日), 我々は、より多くの情報をここで見つけました https://velog.io/@yshjft/BankSystem-2022년-1월-6일テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol