Skip to content

Migrate tests to JUnit Jupiter - #374

Closed
strangelookingnerd wants to merge 3 commits into
OWASP:mainfrom
strangelookingnerd:migrate_to_jupiter
Closed

strangelookingnerd wants to merge 3 commits into
OWASP:mainfrom
strangelookingnerd:migrate_to_jupiter

Conversation

@strangelookingnerd

Copy link
Copy Markdown
Contributor

This PR aims to migrate all tests to JUnit Jupiter. Changes include:

  • Migrate annotations and imports
  • Migrate assertions
  • Remove public visibility for test classes and methods
  • Minor clean up

I am well aware that this is a quite large changeset however I hope that there is still interest in this PR and it will be reviewed.
If there are any questions, please do not hesitate to ping me.

* Migrate annotations and imports
* Migrate assertions
* Remove public visibility for test classes and methods
* Minor code cleanup
* Migrate annotations and imports
* Migrate assertions
* Remove public visibility for test classes and methods
* Minor code cleanup
@jmanico

jmanico commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

I would like to get this in, thank you for doing it. It conflicts with main now only because three test files (HtmlPolicyBuilderTest, HtmlSanitizerTest, SanitizersTest) gained new tests today from #356 and #378. I am rebase-ing into current main and will get this closed out.

@jmanico

jmanico commented Sep 8, 2026

Copy link
Copy Markdown
Member

Thank you again for this. main had moved too far for a clean rebase (every test file changed on both sides and a new JUnit 3 test file landed after this was opened), so I redid the migration on top of current main in #415 with you credited as co-author. It keeps everything this PR set out to do and adds assertThrows, a parameterized examples test, and lambdas for the single-method handlers. #415 will close this one when it merges.

jmanico added a commit that referenced this pull request Sep 8, 2026
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 jmanico closed this in #415 Sep 8, 2026
@strangelookingnerd
strangelookingnerd deleted the migrate_to_jupiter branch September 8, 2026 19:14
daham-13 pushed a commit to daham-13/java-html-sanitizer that referenced this pull request Sep 16, 2026
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 OWASP#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
@github-actions

Copy link
Copy Markdown

🎉 This issue has been resolved in release-20260921.1 (Release Notes)

@github-actions github-actions Bot added the released Issue has been released label Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Issue has been released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants