Add custom exception assertions
- Ngôn ngữ chính
- CSS
- Star
- 26
- Fork
- 32
- Merge trung bình
- 2 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 3
Mô tả
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?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu với phần “2.6.2 Custom Assertions” hiện có trong hướng dẫn AssertJ được liên kết và kiểm tra repository assertj-examples được liên kết để xem các ví dụ assertion hiện tại của nó. Xác nhận các assertion tùy chỉnh cho exception phù hợp với hệ thống phân cấp lớp hiện có như thế nào, sau đó ghi lại một ví dụ bao quát message của exception và các trường chi tiết ở cả hai vị trí.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100