정렬

@RunWith(SpringRunner.class)
@DataJpaTest
public class CommentRepositoryTest {

	@Autowired
	CommentRepository commentRepository;

	@Test
	public void crud() {
		this.createComment(100, "spring data jpa");
		this.createComment(55, "hibernate spring");

		PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Sort.Direction.DESC, "likeCount"));

		Page<Comment> comments = commentRepository.findByCommentContainsIgnoreCase("Spring", pageRequest);
		assertThat(comments.getNumberOfElements()).isEqualTo(2);
		assertThat(comments).first().hasFieldOrPropertyWithValue("likeCount", 100);
	}

	private void createComment(int likeCount, String comment) {
		Comment newComment = new Comment();
		newComment.setComment(comment);
		newComment.setLikeCount(likeCount);
		commentRepository.save(newComment);
	}
}