Skip to content

Add equals/hashCode support for Criteria #1960

Closed
@bigluds

Description

@bigluds

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions