Add custom exception assertions

オープン
#175 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

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

調査の方向性

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

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

説明

Currently, the documentation shows how to extend an assertion in 2.6.2 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

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?

主要言語
CSS
スター
26
フォーク
32
平均マージ
1日 19時間
マージ済み PR(30日)
4

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

assertj/doc のほかの issue

assertj/doc の issue をすべて見る

似ている issue

Documentation の issue をもっと見る

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

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