Add custom exception assertions
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- documentation
Research direction
Start with the existing “2.6.2 Custom Assertions” section in the linked AssertJ guide and inspect the linked assertj-examples repository for its current assertion examples. Confirm how custom exception assertions fit the existing class hierarchy, then document an example covering the exception message and detail fields in both locations.
Written by the indexing model from the issue text.
Description
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?
- Dominant language
- CSS
- Stars
- 26
- Forks
- 32
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from assertj/doc
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 2/5 Half a day Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Ecosystem: ClawMetry — the Qwen Code reader is now free and open source (follow-up to #9294 / #9338) Opencategory/integration priority/P3 scope/documentation status/ready-for-human type/feature-request
Difficulty 1/5 Under an hour Newbie friendliness 84/100