Duplicated assertion method with target class implementing method from interface
まだ誰も着手していません。
評価
調査の方向性
ソースファイルもテストも指定されていません。まず、インターフェースと実装のメソッドをアサーションメソッドに変換するジェネレーターの経路を特定し、次にインターフェース id() とそれを実装するクラスでこのケースを再現してください。生成によって重複した hasId メソッドが生成されなくなり、その動作が回帰テストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Java
- スター
- 72
- フォーク
- 47
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
assertj/assertj-generator のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
assertj/assertj-generator#220 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
assertj/assertj-generator#219 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
assertj/assertj-generator#204 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
assertj/assertj-generator#197 · コメント 7 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
assertj/assertj-generator#196 ·
assertj/assertj-generator の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
infinispan/infinispan#18150 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
opensearch-project/k-NN#3597 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100