Add custom exception assertions
还没有人认领这个 Issue。
- 主要语言
- CSS
- 星标
- 26
- 派生
- 32
- 平均合并
- 2 天 9 小时
- 30 天内合并 PR
- 3
描述
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?
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 AssertJ 指南中现有的“2.6.2 Custom Assertions”部分开始,并检查链接的 assertj-examples 仓库,了解其中当前的 assertion 示例。确认自定义 exception assertion 如何适配现有的类层次结构,然后在两个位置都记录一个涵盖 exception message 和 detail 字段的示例。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100