Closed
Description
It seems that my JUnit tests using Mockito fails because the Unpaged does not fully support equals/hashcode sementic when Sort is specified.
In the tests below, the tests PageableTests#testEqualsOnUnpagedUnsortedCase1 and PageableTests#testEqualsOnUnpagedUnsortedCase2 are success (because there is it the same instance) while the last one PageableTests#testEqualsOnUnpagedSorted fails due to a leak on equals/hashcode sementic (because equals/hashcode sementic is not implemented).
So using Mockito on a repository with Pageable fails when I use a Pageable.unpaged(Sort). Could you, please review the code to correct this issue.
package com.myapp;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
public class PageableTests {
@Test
void testEqualsOnUnpagedUnsortedCase1() {
Assertions.assertThat(Pageable.unpaged()).isEqualTo(Pageable.unpaged());
}
@Test
void testEqualsOnUnpagedUnsortedCase2() {
Assertions.assertThat(Pageable.unpaged(Sort.unsorted())).isEqualTo(Pageable.unpaged(Sort.unsorted()));
}
@Test
void testEqualsOnUnpagedSorted() {
Assertions.assertThat(Pageable.unpaged(Sort.by("code"))).isEqualTo(Pageable.unpaged(Sort.by("code")));
}
}```