Duplicated assertion method with target class implementing method from interface
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
No source file or test is named. Start by locating the generator path that turns interface and implementation methods into assertion methods, then reproduce the case with an interface id() and an implementing class. Done means generation no longer produces duplicate hasId methods, with the behavior covered by a regression test.
Written by the indexing model from the issue text.
Description
Hi @scordio ,
let me thank you first for your work. Because I was looking a long time that we can use records with AssertJ and can remove the templates.
The new version works perfectly in our project. Unfortunately, I found a bug with M4/M5. But maybe isn't bug, because our clever programming isn't that clever ;). Should I open an issue for that?
Short summary of the bug
- We have an Interface X which has method called id()
- We implement this Interface X in several classes. The typical implementation is
String id = "someId"; public String id() { return id; }- When AssertJ creates the *Assert classes it creates the method
hasIdtwice, e.g./** * Verifies that the actual Data's id is equal to the given one. * @param id the given id to compare the actual Data's id to. * @return this assertion object. * @throws AssertionError - if the actual Data's id is not equal to the given one. */ public S hasId(String id) { // check that actual Data we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting id of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // null safe check String actualId = actual.getId(); if (!Objects.deepEquals(actualId, id)) { failWithMessage(assertjErrorMessage, actual, id, actualId); } // return the current assertion for method chaining return myself; } /** * Verifies that the actual Data's id is equal to the given one. * @param id the given id to compare the actual Data's id to. * @return this assertion object. * @throws AssertionError - if the actual Data's id is not equal to the given one. */ public S hasId(String id) { // check that actual Data we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting id of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // null safe check String actualId = actual.id(); if (!Objects.deepEquals(actualId, id)) { failWithMessage(assertjErrorMessage, actual, id, actualId); } // return the current assertion for method chaining return myself; }Simple workaround
Renaming the methodid()togetId()solved the problem and all Assertions classes are created correctly.
Originally posted by @schmuka0501 in https://github.com/assertj/assertj-assertions-generator-maven-plugin/issues/93#issuecomment-3183154411
- Dominant language
- Java
- Stars
- 72
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from assertj/assertj-generator
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
assertj/assertj-generator#220 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
assertj/assertj-generator#219 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
assertj/assertj-generator#204 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
assertj/assertj-generator#197 · 7 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
assertj/assertj-generator#196 ·
All issues in assertj/assertj-generator
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100