Closed
Description
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.
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