Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equals/hashCode support for Unpaged #3061

Closed
bigluds opened this issue Mar 12, 2024 · 2 comments
Closed

Add equals/hashCode support for Unpaged #3061

bigluds opened this issue Mar 12, 2024 · 2 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@bigluds
Copy link

bigluds commented Mar 12, 2024

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

}```
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 12, 2024
@bigluds
Copy link
Author

bigluds commented Mar 12, 2024

Below the JUnit tests results:
image

@mp911de mp911de self-assigned this Mar 12, 2024
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 12, 2024
@mp911de mp911de changed the title Add equals/hashcode support for Unpaged Add equals/hashCode support for Unpaged Mar 12, 2024
@mp911de
Copy link
Member

mp911de commented Mar 12, 2024

Thank you for the enhancement proposal. It makes sense to implement both methods for equality checks.

mp911de added a commit that referenced this issue Mar 12, 2024
@mp911de mp911de added this to the 3.2.4 (2023.1.4) milestone Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants