Skip to content

Commit cf15ec6

Browse files
dfa1claude
andcommitted
test: name exception-action callable result; document convention
Rename the ThrowingCallable from `when` to `result` in the heap-guard tests and document the exception-assertion structure in CLAUDE.md: the callable is the // When, assertThatThrownBy(result) is the // Then. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8f5caac commit cf15ec6

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Built `.dylib/.so/.dll` are git-ignored; they are regenerated from the submodule
5454
- JUnit 5 + Mockito (BDDMockito) + AssertJ. Class under test named `sut`. Every test has
5555
`// Given` / `// When` / `// Then`. BDDMockito only: `given(mock.m()).willReturn(v)` /
5656
`then(...)` (static-import only `given`/`then`, never `willReturn`/`willThrow`).
57+
For exception assertions, capture the action under `// When` as a
58+
`ThrowingCallable result = () -> sut.m(...);` and assert it under `// Then` with
59+
`assertThatThrownBy(result)` — the callable is the When, the assertion is the Then.
5760
- Prefer `@ParameterizedTest` over copy-paste (`@ValueSource`, else `@ArgumentsSource`/named cases).
5861
For large input spaces use seeded-random `@MethodSource` generators — they find corners examples
5962
miss. Put generators in `RandomArrays` (integration) or a similar util; keep counts low (10–30)

zstd/src/test/java/io/github/dfa1/zstd/ZstdSegmentTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.dfa1.zstd;
22

3+
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
34
import org.junit.jupiter.api.Nested;
45
import org.junit.jupiter.api.Test;
56

@@ -110,8 +111,10 @@ void compressRejectsHeapSource() {
110111
MemorySegment dst = arena.allocate(64);
111112

112113
// When compressing from it
114+
ThrowingCallable result = () -> sut.compress(dst, heapSrc);
115+
113116
// Then it fails fast with a clear message instead of a cryptic FFM error
114-
assertThatThrownBy(() -> sut.compress(dst, heapSrc))
117+
assertThatThrownBy(result)
115118
.isInstanceOf(IllegalArgumentException.class)
116119
.hasMessageContaining("native");
117120
}
@@ -126,8 +129,10 @@ void decompressRejectsHeapDestination() {
126129
MemorySegment src = arena.allocate(64);
127130

128131
// When decompressing into it
132+
ThrowingCallable result = () -> sut.decompress(heapDst, src);
133+
129134
// Then it fails fast with a clear message instead of a cryptic FFM error
130-
assertThatThrownBy(() -> sut.decompress(heapDst, src))
135+
assertThatThrownBy(result)
131136
.isInstanceOf(IllegalArgumentException.class)
132137
.hasMessageContaining("native");
133138
}
@@ -139,8 +144,10 @@ void decompressedSizeRejectsHeapFrame() {
139144
MemorySegment heapFrame = MemorySegment.ofArray(new byte[8]);
140145

141146
// When reading its decompressed size
147+
ThrowingCallable result = () -> Zstd.decompressedSize(heapFrame);
148+
142149
// Then it fails fast with a clear message instead of a cryptic FFM error
143-
assertThatThrownBy(() -> Zstd.decompressedSize(heapFrame))
150+
assertThatThrownBy(result)
144151
.isInstanceOf(IllegalArgumentException.class)
145152
.hasMessageContaining("native");
146153
}

0 commit comments

Comments
 (0)