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