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

UnambiguousRepresentation computes same output when types have same name but different packages #3084

Open
scordio opened this issue Jun 15, 2023 · 0 comments · May be fixed by #3223
Open
Labels
type: improvement A general improvement

Comments

@scordio
Copy link
Member

scordio commented Jun 15, 2023

The error message produced by isEqualTo prints out the class name when the values have the same representation. While this helps disambiguate types with different class names, it doesn't help when the two types have the same name but different packages.

For example, assuming two enum types, both having a VALUE constant:

  • org.example.pkg1.Enum1
  • org.example.pkg2.Enum1

the following:

assertThat(org.example.pkg1.Enum1.VALUE).isEqualTo(org.example.pkg2.Enum1.VALUE);

yields:

org.opentest4j.AssertionFailedError: 
expected: "VALUE (Enum1@d6da883)"
 but was: "VALUE (Enum1@5cdd8682)"

In such cases, printing the fully qualified class name would make the message clearer:

org.opentest4j.AssertionFailedError: 
expected: "VALUE (org.example.pkg1.Enum1@d6da883)"
 but was: "VALUE (org.example.pkg2.Enum1@5cdd8682)"

Any assertion that uses UnambiguousRepresentation which relies on Representation::unambiguousToStringOf could benefit from this improvement, including the recursive comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A general improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant