assertj / assertj/doc

Add custom exception assertions

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

説明

Currently, the documentation shows how to extend an assertion in [2.6.2 Custom Assertions](https://assertj.github.io/doc/#assertj-core-custom-assertions) but there is no documentation for custom exception asserts, which seems to use a slightly different mechanism with some other class hierarchy.

It would be nice to include this in the guide and in the [examples repository](https://github.com/assertj/assertj-examples)

The goal for this section in the guide will be to present, given a custom exception, a way to assert on the specific fields in that class. For instance, given a custom exception:
```
package com.example.exception;

public class DetailException extends RuntimeException {

private String detail;

public DetailException(String message, String detail) {
super(message);
this.detail = detail;
}

public String getDetail() {
return detail;
}
}
```

and a business logic throwing this exception
```
package com.example.thrower;

import com.example.exception.DetailException;

public class DetailExceptionThrower {

public void throwException() {
throw new DetailException("message", "a detailed exception explanation");
}
}
```

write an extension to write a test like:
```
package com.example.thrower;

import org.junit.jupiter.api.Test;

import static org.assertj.extension.DetailExceptionAssertions.assertThatDetailException;

class DetailExceptionThrowerCustomAssertionTest {

private final DetailExceptionThrower underTest = new DetailExceptionThrower();

@Test
void test_customAssertion() {
assertThatDetailException()
.isThrownBy(underTest::throwException)
.withMessage("message")
.withDetail("a detailed exception explanation");
}
}
```

is it even possible to write an extension like this?

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

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

リンク先の AssertJ ガイドにある既存の「2.6.2 Custom Assertions」セクションから始め、リンク先の assertj-examples リポジトリを調べて、現在の assertion の例を確認してください。カスタム例外 assertion が既存のクラス階層にどのように適合するかを確認し、例外メッセージと詳細フィールドを扱う例を両方の場所に記載してください。

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

評価

技術スタック
java
領域
documentation
issue の種類
ドキュメント
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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