usingRecursiveComparison() returns false positive when comparing to a Spring Data JPA projection
- Dominant language
- Java
- Stars
- 2.8k
- Forks
- 788
- Avg merge
- 14h 57m
- Merged PRs (30d)
- 36
Description
* spring-boot-starter-parent version: 3.3.2 (with managed dependency versions)
* assertj core version: 3.25.3
* java version: 17
* test framework version: junit-jupiter-api 5.10.3
**Test case reproducing the bug**
```java
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface PersonRepo extends JpaRepository {
@Entity
public static class PersonEntity {
@Id
private String name;
}
public interface Person {
String getName();
}
@Query(value = "SELECT 'alice' as name")
Person getPerson();
}
```
```java
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
public class PersonRepoTest {
@Autowired
private PersonRepo personRepo;
private record PersonImpl(String getName) implements PersonRepo.Person {
}
@Test
public void test() {
PersonRepo.Person alice = personRepo.getPerson();
PersonRepo.Person bob = new PersonImpl("bob");
// Recursive comparison incorrectly asserts that alice and bob are the same
assertThat(alice).usingRecursiveComparison().isEqualTo(bob);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.