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

Comparing only fields does not work with List Of Objects. It is passed without error, although mismatch is present #2994

Closed
avishekjana-89 opened this issue Mar 21, 2023 · 2 comments
Labels
theme: recursive comparison An issue related to the recursive comparison
Milestone

Comments

@avishekjana-89
Copy link

avishekjana-89 commented Mar 21, 2023

Comparing only fields does not work with List Of Objects. It is passed without error, although mismatch is present.

  • assertj core version: 3.24.2
  • java version: Java 1.8
  • test framework version: TestNG 7.4.0
  • os (if relevant): NA

//sample class
public class Student {
String name;
String subject;
int rollNo;

public Student(String name, String subject, int rollNo) {
    this.name = name;
    this.subject = subject;
    this.rollNo = rollNo;
}

}

Add a test case showing the bug that we can run

//Test class
public class AssertTest {

@Test
public void ComparingByFields(){
    List<Student> actual = new ArrayList<>();
    actual.add(new Student("John", "math", 1));
    actual.add(new Student("Rohit", "english", 2));

    List<Student> expected = new ArrayList<>();
    expected.add(new Student("Jon", "math", 1));
    expected.add(new Student("Rohit", "english", 2);

    assertThat(actual)
            .usingRecursiveComparison()
            .comparingOnlyFields( "name", "subject")
            .isEqualTo(expected);

}

}

It should throw an error on 'name' property because of mismatch on first object.

@avishekjana-89
Copy link
Author

@joel-costigliola can you please have a look?

@scordio scordio added the theme: recursive comparison An issue related to the recursive comparison label Mar 25, 2023
@joel-costigliola
Copy link
Member

Thanks for reporting this @avishekjana-89, we will look at it for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: recursive comparison An issue related to the recursive comparison
Projects
None yet
Development

No branches or pull requests

3 participants