Skip to content

Add equals/hashCode support for Criteria #1960

New issue

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

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

Already on GitHub? # to your account

Closed
bigluds opened this issue Dec 14, 2024 · 1 comment
Closed

Add equals/hashCode support for Criteria #1960

bigluds opened this issue Dec 14, 2024 · 1 comment
Assignees
Labels
type: enhancement A general enhancement

Comments

@bigluds
Copy link

bigluds commented Dec 14, 2024

It seems that my JUnit tests using Mockito fails because the Criteria does not fully support equals/hashcode semantic.

In the tests below, the test CriteriaTests#testEqualsCriteriaSameInstance is success (because there is it the same instance) while the other one CriteriaTests#testEqualsCriteriaDifferentInstances fails due to a leak on equals/hashcode sementic (because equals/hashcode sementic is not implemented).

So using Mockito on a repository with Criteria fails when I use a Criteria (like R2dbcEntityTemplate). Could you, please review the code to correct this issue ?

package com.myapp;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.data.relational.core.query.Criteria;

@Tag("UnitTest")
public class CriteriaTests {

    @Test
    void testEqualsCriteriaSameInstance() {
        Criteria c1 = Criteria.where("status").in("PUBLISHED", "DRAFT");
        Assertions.assertThat(c1).isEqualTo(c1);
    }

    @Test
    void testEqualsCriteriaDifferentInstances() {
        Criteria c1 = Criteria.where("status").in("PUBLISHED", "DRAFT");
        Criteria c2 = Criteria.where("status").in("PUBLISHED", "DRAFT");
        Assertions.assertThat(c1).isEqualTo(c2);
    }

}

Please find below the JUnit test's results:
image

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 14, 2024
@schauder schauder added the type: enhancement A general enhancement label Dec 16, 2024
@mp911de mp911de removed the status: waiting-for-triage An issue we've not yet triaged label Dec 16, 2024
@schauder schauder added this to the 3.5 M1 (2025.0.0) milestone Dec 17, 2024
@bigluds
Copy link
Author

bigluds commented Dec 18, 2024

I've just integrated the 3.5 M1 (2025.0.0-SNAPSHOT) in my projet for testing purpose and I confirm that it works fine.
Many thanks for the correction.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants