Repository navigation
Migrate the test suite to JUnit Jupiter - #415
Merged
Merged
Conversation
The tests were JUnit 3 `TestCase` subclasses run through the JUnit 4 provider, with `public static final void test*()` methods that only the JUnit 3 reflection runner would find. They now run on JUnit Jupiter 5.14 (the last line that still supports the Java 8 target) via the JUnit BOM. * Every `test*` method carries `@Test` and is package-private and non-static; JUnit 3/4 message-first assertions are reordered to the Jupiter `(expected, actual, message)` form. * `setUp`/`tearDown` overrides become named `@BeforeEach`/`@AfterEach` methods; the AntiSamy `suite()` and the JUnit 3 `VerboseTestRunner` are gone. * Expected exceptions use `assertThrows`; the example programs run as a `@ParameterizedTest`, one case per example, and the diagnostic output of a failing example now reaches the real stderr. * The nested-anchor tag balancing test that was hidden behind a `failingtest` name prefix is `@Disabled` with a reason, so it shows up as skipped instead of vanishing. * Single-method anonymous `Handler`, `AttributePolicy`, `ElementPolicy`, `Function` and `Runnable` classes are lambdas; stray tab indentation in four test files is normalized. * `java8-shim` and `java10-shim` have no tests and drop their JUnit dependency. Per-class test counts are unchanged from main (378), plus the two extra example cases and the newly visible skipped test. `./mvnw verify` passes on JDK 11, 17, 21 and 25, and `-Djunit.seed=<seed>` still replays the fuzzers. Supersedes #374. Co-authored-by: strangelookingnerd <49242855+strangelookingnerd@users.noreply.github.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK
Reviewing #374 against #415 turned up cleanups the contributor made that the fresh migration lacked: String.join in place of stream/collect joins, assertArrayEquals for the code unit comparison, lambdas for the preprocessor wrappers and the benchmark's error handlers, an enhanced for loop with StandardCharsets over the AntiSamy base64 inputs, StringBuilder for StringBuffer, and redundant `final` dropped from private static methods. Co-authored-by: strangelookingnerd <49242855+strangelookingnerd@users.noreply.github.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK
jmanico
force-pushed
the
junit5-migration
branch
from
September 8, 2026 04:47
25989ff to
331e367
Compare
* HtmlPolicyBuilderTest.apply passed its failing Handler as the unused context argument of PolicyFactory.sanitize, so renderer errors never failed any builder test. It now renders through a handler that fails the test, applying the factory's preprocessor via a new package-private PolicyFactory.preprocessor() accessor so behaviour is otherwise unchanged. * ExamplesTest rethrows the example's own exception instead of the reflective InvocationTargetException wrapper, and takes its cases straight from AllExamples.CLASSES with @FieldSource. * The postprocessor wrappers in HtmlPolicyBuilderTest use the same lambda form as the preprocessor ones; a `throws Exception` clause that the StandardCharsets change made dead and the last Eclipse-only "javadoc" suppression token are gone. * The @disabled reason on the nested-anchor balancing test notes that its expected output also needs settling. * java8-shim/pom.xml drops the empty <dependencies> element. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK
jmanico
force-pushed
the
junit5-migration
branch
from
September 8, 2026 04:49
331e367 to
4860f67
Compare
The worker task only caught Exception, so an AssertionError from the lexer or a StackOverflowError in a pool thread went to the default uncaught-exception handler and the test still passed without printing the seed. Catch Throwable, and rethrow Errors as themselves. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK
* FuzzyTestCase seeds a final Random in its field initializer, rejects a malformed junit.seed instead of silently using the clock, and registers a TestWatcher that prints the seed of any failed fuzz test. The three fuzzers drop their ad-hoc seed printing (which appended an "L" that the parser then refused) and become package-private like the other tests. * CssFuzzerTest's slow-input watchdog could never fire: it looped while the input was null and was started only after the input was set. It now runs for the whole test, reports each slow input once, and is interrupted at the end. * The nested-anchor tag balancing test is enabled with the well-formed output the balancer actually produces; its golden closed an <a> that was never opened. * Error lists are compared as lists with assertIterableEquals rather than as newline-joined strings, and CssTokensTest drops its redundant toString pre-checks. * HtmlStreamRendererTest loses a @beforeeach that reset per-instance fields, AntiSamyTest uses Handler.PROPAGATE, and the tag balancing handler includes the renderer's message in its failure. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK
|
🎉 This issue has been resolved in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes #374 by @strangelookingnerd on top of current
main. That branch had drifted far behind (every test file changed on both sides, andElidedCharactersTestwas added after it was opened), so the migration was redone from scratch with the same goals and the original author credited as co-author. A full multi-angle review then ran against the result; everything it found is fixed in the later commits.What changes
java8-shimandjava10-shimhave no tests and drop their JUnit dependency.test*method is now@Test, package-private and non-static. JUnit 3's reflection runner foundpublic static final void test*()methods; Jupiter silently ignores static ones, so this was the main thing to get right.(expected, actual, message)form (65 call sites, done with a paren-aware parser and independently re-verified by the review).setUp/tearDownoverrides become named@BeforeEach/@AfterEachmethods;AntiSamyTest.suite()and the JUnit 3VerboseTestRunnerare removed.assertThrows; error lists are compared withassertIterableEquals;ExamplesTestruns each example as its own case via@FieldSourceand rethrows the example's real exception.Handler/AttributePolicy/ElementPolicy/HtmlStreamEventProcessor/Function/Runnableclasses are lambdas; stray tab indentation is normalized.Strengthened by the review
FuzzyTestCaseregisters aTestWatcherthat printsreplay it with -Djunit.seed=<seed>on any failure, and rejects a malformed seed instead of silently falling back to the clock. The sanitizer fuzzer's worker now catchesThrowable, so anAssertionErroror stack overflow in a pool thread fails the test instead of vanishing.CssFuzzerTest's slow-input watchdog, which could never fire, works.HtmlPolicyBuilderTest.applyused to pass its failing handler as an unused context object, so renderer errors never failed any of ~40 tests. It now renders through a real failing handler, using a new package-privatePolicyFactory.preprocessor()accessor so the preprocessor pipeline is unchanged. This is the only production-source change, and it adds no public API.failingtestname prefix expected malformed HTML. Its golden is corrected to the well-formed output the balancer actually produces, and it is enabled and passing.Verification
Per-class counts are identical to
main; the +3 are the two extra parameterized example cases and the newly enabled nested-anchor test../mvnw verifypasses on JDK 11, 17, 21 and 25 in CI and locally.Closes #374
🤖 Generated with Claude Code
https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK