Skip to content

Query instances with the same limit are not equal anymore #4584

Closed
@Quexley

Description

@Quexley

In our unit tests we mock some MongoTemplate.find(Query) methods where the queries have with(Pageable pageable) applied to them. After upgrading Spring Boot from 3.x.x to 3.2.0, our test no longer works.

After some digging it seems like the issue is inside the equals implementation of org.springframework.data.mongodb.core.query.Query#querySettingsEquals. The limit is compared by == but is no longer an int but a org.springframework.data.domain.Limit instead.

querySettingsEquals:
image

limit:
image

As a result, if I create two Queries each with the same limit, they can never be equal. In our case this prevents us from mocking, since Mockito will not be able to match the mocked method:

when(mongoTemplate.find(eq(new Query().limit(5)), eq(Customer.class))).thenReturn(someCustomers);

assertThat(mongoTemplate.find(new Query().limit(5), Customer.class)).isEqualTo(someCustomers); // assertion fails

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions