java.lang.AssertionError: 
Expected size: 10 but was: 0 in:
Page 2 of 1 containing UNKNOWN instances
@DisplayName("[happy] - 특정 게시글이 가진 대댓글을 조회한다.")
@Test
void findAllById() {
    //given
    BoardSubComment savedBoardSubComment = makeSavedBoardSubComment();
    Long boardId = 1L;
    Pageable pageable = PageRequest.of(1, 10);

    //when
    Page<BoardSubComment> result = boardSubCommentRepository.findAllById(boardId, pageable);

    //then
    assertThat(savedBoardSubComment).isNotNull();
    assertThat(result).isNotNull();
    assertThat(result).hasSize(10);
    assertThat(result).isInstanceOf(Page.class);
}
@Repository
public interface BoardSubCommentRepository extends JpaRepository<BoardSubComment, Long> {

    Page<BoardSubComment> findAllById(Long boardId, Pageable pageable);
}

<aside> 3️⃣ 해결도전1

</aside>

@DisplayName("[happy] - 특정 게시글이 가진 대댓글을 조회한다.")
@Test
void findAllById() {
    //given
    BoardSubComment savedBoardSubComment = makeSavedBoardSubComment();
    Long boardId = 1L;
    Pageable pageable = PageRequest.of(0, 10);

    //when
    Page<BoardSubComment> result = boardSubCommentRepository.findAllById(boardId, pageable);

    //then
    assertThat(savedBoardSubComment).isNotNull();
    assertThat(result).isNotNull();
    // 기대하는 크기를 실제 데이터의 크기에 맞게 조정
    assertThat(result).hasSize(Math.min(10, result.getSize()));
    assertThat(result).isInstanceOf(Page.class);
}
  1. PageRequest.of를 (1,10) 에서 (0,10)으로 바꾼다.
  2. assertThat에서 hasSize에서 10과 result의 사이즈중에 작은걸로 검증하도록 만들었다.
java.lang.AssertionError: 
Expected size: 10 but was: 1 in:
Page 1 of 1 containing com.jinan.profile.domain.board.BoardSubComment instances

<aside> 3️⃣ 해결도전2

</aside>

@DisplayName("[happy] - 특정 게시글이 가진 대댓글을 조회한다.")
@Test
void findAllById() {
    //given
    BoardSubComment savedBoardSubComment = makeSavedBoardSubComment();
    Long boardId = 1L;
    Pageable pageable = PageRequest.of(0, 10);

    //when
    Page<BoardSubComment> result = boardSubCommentRepository.findAllById(boardId, pageable);

    //then
    assertThat(savedBoardSubComment).isNotNull();
    assertThat(result).isNotNull();
    assertThat(result).hasSize(1);
    assertThat(result).isInstanceOf(Page.class);
}