Skip to content

Commit cdac940

Browse files
committed
Clarify @test throws-clause review guidance
1 parent 71e7474 commit cdac940

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

.github/agents/code-review-and-fix.agent.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ Auto-fix boundaries:
156156
already valid AssertJ assertions; do not wrap them in `assertThat(...).isTrue()`
157157
- AssertJ `.as(...)` descriptions and `.withFailMessage(...)` in tests — remove them
158158
and prefer direct assertions whose failure output already exposes the unexpected values
159+
- `@Test` method `throws` clauses — limit them to a single exception type and keep that type as
160+
specific as possible.
159161
- deterministic semconv constant handling aligned with repository rules
160162
- missing test-task wiring patterns with clear canonical form
161163
- missing `testInstrumentation` cross-version references — when a javaagent module belongs

.github/agents/knowledge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Load only files relevant to the current scope to reduce noise and avoid over-con
1818
| `javaagent-singletons-patterns.md` | `*Singletons` holder classes, singleton accessors, callers of singleton accessors/fields |
1919
| `library-patterns.md` | Library instrumentation telemetry, builder, getter, or setter pattern changes |
2020
| `module-naming.md` | New or renamed modules or packages; settings includes |
21-
| `testing-general-patterns.md` | Test files in scope — assertion style, resource cleanup patterns, attribute assertion patterns, `satisfies()` lambda usage |
21+
| `testing-general-patterns.md` | Test files in scope — assertion style, test method signatures and throws clauses, resource cleanup patterns, attribute assertion patterns, `satisfies()` lambda usage |
2222
| `testing-experimental-flags.md` | `testExperimental` task or experimental span-attribute assertions |
2323
| `testing-semconv-stability.md` | Semconv opt-in modes, `emitOld*`/`emitStable*`, `maybeStable`, Semconv test tasks |
2424

.github/agents/knowledge/general-rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ When a "Knowledge File" is listed, load it from `knowledge/` before reviewing th
2525
| Javaagent | Incorrect `classLoaderMatcher()` | `classLoaderMatcher()` override that is redundant (muzzle already handles it) or missing when needed (muzzle cannot distinguish version range) | `javaagent-module-patterns.md` |
2626
| Semconv | Library vs javaagent semconv constant usage | Semconv constants/assertions ||
2727
| Semconv | Dual semconv testing | `SemconvStability`, `maybeStable`, semconv Gradle tasks | `testing-semconv-stability.md` |
28-
| Testing | General test patterns | Test files in scope — assertion style, resource cleanup, attribute assertions | `testing-general-patterns.md` |
28+
| Testing | General test patterns | Test files in scope — assertion style, test method signatures and throws clauses, resource cleanup, attribute assertions | `testing-general-patterns.md` |
2929
| Testing | Experimental flag tests | `testExperimental`, experimental attribute assertions, `experimental` flags in JVM args or system properties | `testing-experimental-flags.md` |
3030
| Library | TelemetryBuilder/getter/setter patterns | Library instrumentation classes | `library-patterns.md` |
3131
| API | Deprecation and breaking-change policy | Public API changes | `api-deprecation-policy.md` |

.github/agents/knowledge/testing-general-patterns.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Quick Reference
44

55
- Use when: test files (`**/src/test/**`) are in scope
6-
- Review focus: assertion style, test class visibility, resource cleanup patterns, attribute assertion patterns
6+
- Review focus: assertion style, test class visibility, test method signatures and throws clauses, resource cleanup patterns, attribute assertion patterns
77

88
## Assertion Framework
99

@@ -12,6 +12,16 @@
1212
- Do not use AssertJ `.as(...)` descriptions or `.withFailMessage(...)` in tests.
1313
Prefer direct assertions whose failure output shows the unexpected values.
1414

15+
## Test Method Throws Clauses
16+
17+
- On methods annotated with `@Test`, keep the `throws` clause to a single exception type.
18+
Do not declare multiple checked exception types on a test method.
19+
- Be as specific as possible. Prefer the narrowest single checked type that the test body
20+
actually exposes instead of broad forms such as `throws Exception` or a multi-exception list.
21+
- If the test only blocks on `Future.get(...)` / `CompletableFuture.get(...)`, prefer refactoring to
22+
`join()` or another non-checked wait path when that keeps the test clear, rather than widening the
23+
test method to `throws Exception` just to avoid a multi-exception `throws` clause.
24+
1525
## Test Resource Cleanup
1626

1727
- In JUnit tests, when an `AutoCloseable` is intended to remain live for most or all of the test

0 commit comments

Comments
 (0)