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

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

Closed
Quexley opened this issue Dec 8, 2023 · 1 comment
Closed

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

Quexley opened this issue Dec 8, 2023 · 1 comment
Assignees
Labels
type: regression A regression from a previous release

Comments

@Quexley
Copy link

Quexley commented Dec 8, 2023

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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 8, 2023
@mp911de mp911de added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 8, 2023
@mp911de mp911de self-assigned this Dec 8, 2023
@mp911de mp911de closed this as completed in e20d12f Dec 8, 2023
mp911de added a commit that referenced this issue Dec 8, 2023
@mp911de mp911de added this to the 4.2.1 (2023.1.1) milestone Dec 8, 2023
@mp911de
Copy link
Member

mp911de commented Dec 8, 2023

That's fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

3 participants