assertj / assertj/assertj-generator
Assertion compilation fails when class has a template field
- 主要言語
- Java
- スター
- 72
- フォーク
- 47
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 2
説明
Generations plugin versions in maven:
```xml
org.assertj
assertj-assertions-generator-maven-plugin
2.2.0
```
Test class
```java
package testassertj;
import lombok.Data;
@Data
public class TemplateClassField {
protected T model;
}
```
Generated assertion class:
```java
package testassertj;
import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.util.Objects;
/**
* {@link TemplateClassField} specific assertions - Generated by CustomAssertionGenerator.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
public class TemplateClassFieldAssert extends AbstractObjectAssert {
/**
* Creates a new {@link TemplateClassFieldAssert} to make assertions on actual TemplateClassField.
* @param actual the TemplateClassField we want to make assertions on.
*/
public TemplateClassFieldAssert(TemplateClassField actual) {
super(actual, TemplateClassFieldAssert.class);
}
/**
* An entry point for TemplateClassFieldAssert to follow AssertJ standard assertThat() statements.
* With a static import, one can write directly: assertThat(myTemplateClassField) and get specific assertion with code completion.
* @param actual the TemplateClassField we want to make assertions on.
* @return a new {@link TemplateClassFieldAssert}
*/
@org.assertj.core.util.CheckReturnValue
public static TemplateClassFieldAssert assertThat(TemplateClassField actual) {
return new TemplateClassFieldAssert(actual);
}
/**
* Verifies that the actual TemplateClassField's model is equal to the given one.
* @param model the given model to compare the actual TemplateClassField's model to.
* @return this assertion object.
* @throws AssertionError - if the actual TemplateClassField's model is not equal to the given one.
*/
public TemplateClassFieldAssert hasModel(T model) {
// check that actual TemplateClassField we want to make assertions on is not null.
isNotNull();
// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting model of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
// null safe check
T actualModel = actual.getModel();
if (!Objects.areEqual(actualModel, model)) {
failWithMessage(assertjErrorMessage, actual, model, actualModel);
}
// return the current assertion for method chaining
return this;
}
}
```
Compilation fails on ` public TemplateClassFieldAssert hasModel(T model) {` method:
```
[ERROR] /C:/java/myproject/target/generated-test-sources/assertj-assertions/testassertj/TemplateClassFieldAssert.java:[37,44] cannot find symbol
[ERROR] symbol: class T
[ERROR] location: class testassertj.TemplateClassFieldAssert
```
**Expected behaviour:**
Generated assert class is also `` templated, so that `hasModel(T model)` compiles successfully.
コントリビューションガイド
調査の方向性
示されている Maven プラグイン設定と TemplateClassField の例で失敗を再現し、その後、アサーション・クラスとそのメソッドシグネチャを生成するジェネレーターのパスを調査します。生成されたアサーションが型パラメーターを保持し、hasModel(T model) メソッドがコンパイルでき、テンプレートフィールドのケースを回帰テストでカバーできれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- build-system, testing
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 50/100