assertj / assertj/assertj-generator

Feature: Create "unwrapped" overload for `hasX` if X is a value type

オープン
#159 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
72
フォーク
47
平均マージ
1日 16時間
マージ済み PR(30日)
2

説明

This is potentially a little vague in its broadness, but here goes.

Say we have a value class like e.g.

```java
@Value
class AccountNumber {
String rawValue;
}
```

If another class (for which we generate assertions) has a property of this type, we can assert:

```java
assertThat(someObject).hasAccountNumber(new AccountNumber("abc"))
```

Nicer would be:

```java
assertThat(someObject).hasAccountNumber("abc")
```

The generator could look for constructors, static `_.of` methods, and other popular patterns. It's not clear to me if there should be a limit on the length of the parameter list. Anyway, the desired implementation seems straight-forward:

```java
public S hasAccountNumber(String accountNumberRawValue) {
return hasAccountNumber(new AccountNumber(fooRawValue));
}
```

As an alternative, there could be an annotation like e.g.

```java
@AssertionAlias
static Foo of(String rawValue) { ... }
```

On a property `Foo bar`, this would cause additional generation of something like

```java
public S hasBar(String fooRawValue) {
return hasBar(Foo.of(fooRawValue));
}
```

PS: This is probably easily done for specific use cases in any given project using templates, but I don't see documentation for a way to inject custom templates when using the generator through the Maven plugin.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

ソースファイルもテストも指定されていません。まず、issue で言及されている generator の Maven プラグインのパスと既存のテンプレートカスタマイズ機構から始め、その後、生成される hasX メソッドがどのように定義されているかを確認してください。実装の前に、サポートする値型の構築パターン、パラメーターの上限、アノテーションベースのエイリアスを対象範囲に含めるかどうかについて合意してください。選択した動作が仕様化され、生成された出力のテストでカバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。