BankSystem, 2022년 1월 6일

yshjft·2022년 1월 6일
0

Bank System

목록 보기
6/14

spring data jpa에서 paging 할 경우 테스트

@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));
    }

spring data jpa에서 paging을 할 경우 위와 같이 하자! List를 new PageImpl<>()을 통해 Page 객체(?)를 만들어 사용하면 된다.

profile
꾸준히 나아가자 🐢

0개의 댓글