Skip to content

test: move the tests to JUnit 5 - #194

Merged
uniqueg merged 7 commits into
devfrom
test/167-junit-5
Nov 16, 2026
Merged

uniqueg merged 7 commits into
devfrom
test/167-junit-5

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Moves all unit and integration tests from JUnit 4 (vintage engine) to JUnit Jupiter, and drops JUnit 4, the vintage engine, system-rules and the --add-opens of Surefire's argLine.

  • Jupiter lifecycle annotations and assertions (messages last), assertThrows instead of @Test(expected) (wrapping only the call that throws), hamcrest's MatcherAssert
  • Spring Boot's test annotations instead of SpringRunner (@ExtendWith(SpringExtension.class) where only plain Spring test annotations are used), MockitoExtension instead of MockitoJUnitRunner
  • WireMockExtension (with failOnUnmatchedRequests(true), as WireMockRule had) instead of WireMockRule, OutputCaptureExtension instead of OutputCaptureRule, @TempDir instead of TemporaryFolder, @ParameterizedTest instead of the Parameterized runner
  • one @BeforeEach in TesKubernetesConverterTest, as Jupiter doesn't order several of them
  • the test of an unreachable user info endpoint points the client at a closed port instead of stopping the WireMock server (WireMockExtension has no stop())

Production change (minimal seam): KubernetesObjectsSupplier reads CONFIGMAP, CONFIGMAPNAMESPACE and CONFIGMAPKEY through Spring's Environment (a new constructor parameter, injected by Spring) instead of System.getenv, so that tests set them with a MockEnvironment instead of system-rules' EnvironmentVariables. Deployments that set these environment variables behave as before (unset, empty and set values alike); as with any Spring setting, they can now also come from system properties, arguments or SPRING_APPLICATION_JSON.

Docs: docs/development.md describes the Jupiter setup; docs/configuration.md gets the so far undocumented CONFIGMAP* settings (separate commit).

The migration was done with a script plus hand edits rather than the OpenRewrite recipe, whose own downloader couldn't get through the local sandbox's proxy.

Closes #167

Verification

  • ./mvnw clean verify (Java 21): BUILD SUCCESS; 18562 unit tests and 122 integration tests (after merging dev with fix: honour forwarded headers outside Kubernetes #193 and moving its new ForwardedHeadersIT), 0 failures; the same count per test class as on dev, plus one new test of a custom ConfigMap key and namespace (from the Sourcery review); the JaCoCo check (100% lines and branches) passes
  • ./mvnw spotless:check checkstyle:check (Java 8, as the Lint job): BUILD SUCCESS
  • ./mvnw dependency:list -DincludeScope=test: no junit:junit, vintage engine or system-rules left
  • CI: all checks green on the PR (Test, Lint, Docs, Smoke test, Scan image, CodeQL, Codecov patch and project, CI passed)

Declined review findings

  • Shared helpers for the repeated WireMockExtension declarations of the integration tests, and static (per-class) WireMock servers: behaviour-preserving as is (the rules also restarted per test); a possible follow-up, kept out to keep this PR a 1:1 move
  • Dropping public from test classes and methods, and replacing hamcrest's deprecated isEmptyOrNullString: style only, kept out to keep the diff small
  • A Spring-context test that the CONFIGMAP environment variable reaches the Environment: that is Spring Boot's own SystemEnvironmentPropertySource; the new code is fully covered with MockEnvironment

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 4 commits November 16, 2026 04:31
Move all unit and integration tests from JUnit 4 (vintage engine) to
JUnit Jupiter:

- lifecycle annotations, Jupiter assertions (messages last),
  assertThrows instead of @test(expected), hamcrest's MatcherAssert
- Spring Boot's test annotations instead of SpringRunner, the Spring
  extension where only plain Spring test annotations are used, and
  MockitoExtension instead of MockitoJUnitRunner
- WireMockExtension instead of WireMockRule, OutputCaptureExtension
  instead of OutputCaptureRule, @tempdir instead of TemporaryFolder,
  and a @ParameterizedTest instead of the Parameterized runner
- one @beforeeach in TesKubernetesConverterTest, as Jupiter doesn't
  order several of them

KubernetesObjectsSupplier reads CONFIGMAP, CONFIGMAPNAMESPACE and
CONFIGMAPKEY through Spring's Environment, which includes the
environment variables, instead of System.getenv, so that the tests set
them with a MockEnvironment instead of system-rules'
EnvironmentVariables. Drop the vintage engine, system-rules and the
--add-opens of Surefire that EnvironmentVariables needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
CONFIGMAP, CONFIGMAPNAMESPACE and CONFIGMAPKEY were missing from the
configuration reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- WireMock servers fail on unmatched requests again, as WireMockRule
  did (WireMockExtension doesn't by default)
- CapturedOutput as a parameter of the tests that read it, except
  where shared helpers read it
- wireMockConfig() for all WireMock options
- the configuration reference names all the cases in which a security
  context ConfigMap stops TESK API from starting

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Inject Spring’s Environment into KubernetesObjectsSupplier and use it to resolve the ConfigMap name, namespace, and key instead of reading the process environment directly.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplier.java L70-89 (+3 small edits)

Configuration

Remove the JUnit Vintage and system-rules dependencies and drop the module-opening arguments that were needed by system-rules.

  • pom.xml L146 (removed lines), L239-242

Documentation

Document the ConfigMap settings and describe the JUnit Jupiter conventions and test extensions used by the project.

  • docs/configuration.md L29
  • docs/development.md L62-75

Tests

Migrate unit and integration tests to JUnit Jupiter and its extensions, update assertion and lifecycle APIs, and cover the Environment-based ConfigMap settings.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ApiDocsAliasIT.java L13, L20 (removed lines), L29 (removed lines)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/AuthErrorResponsesIT.java L16-20, L56-61 (+3 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/AuthIT.java L15-19, L53-68 (+2 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ClaimAuthIT.java L13-17, L54-69 (+2 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ForwardedHeadersIT.java L12, L19 (removed lines), L28 (removed lines)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/LegacyUserLabelsIT.java L11-15, L44-59 (+2 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/MockUtil.java L7-122 (7 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/NoAuthIT.java L66-74 (+4 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ServiceInfoNoAuthIT.java L7, L12 (removed lines), L18 (removed lines)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ServiceInfoTokenRequiredIT.java L12-16, L43-48 (+3 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/SingleTaskJobsIT.java L61-66 (+4 small edits)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiAuthIT.java L11, L19 (removed lines), L25 (removed lines)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiDisabledIT.java L9, L14 (removed lines), L19 (removed lines)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiEnabledAuthIT.java L9, L17 (removed lines), L23 (removed lines)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiEnabledIT.java L10, L15 (removed lines), L21 (removed lines)
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/trs/TrsToolClientIT.java L3-71 (6 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/TeskApplicationTests.java L3, L5 (removed lines)
  • src/test/java/uk/ac/ebi/tsc/tesk/config/CustomErrorHandlerTest.java L3-4, L9
  • src/test/java/uk/ac/ebi/tsc/tesk/config/TraceInterceptorConfigurationTest.java L16
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/AuthenticatedUserTest.java L3-6, L12
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ClaimAuthorisationTest.java L3-8, L14, L99-120
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/CustomAuthenticationEntryPointTest.java L3-4, L9
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ElixirPrincipalExtractorTest.java L3-19 (4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/GroupNamesSecurityExtractorTest.java L3, L6 (removed lines), L11
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ServiceClientTokenServicesTest.java L8-17, L48-54, L74-79 (+14 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ServiceInfoPublicSettingTest.java L3-6
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserCreatorTest.java L3-7, L14
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserDetailsServiceTest.java L5
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserInfoTokenIntrospectorTest.java L16-35, L50-72, L156-163 (+4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserTest.java L9
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/ApiDocsConfigurationTest.java L10
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/ApiDocsFileTypeTest.java L11, L15 (removed lines), L23 (removed lines)
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/DeprecatedClientSecretWarningTest.java L3-8
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerConfigAuthTest.java L12
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerOAuthClientSecretTest.java L11-16, L45-48 (+4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerUiDisabledConditionTest.java L3-9, L46-58
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerUiEnabledConditionTest.java L3-9, L41-43
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/config/KubernetesClientConfigTest.java L11, L19-20, L25-30
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/config/KubernetesJsonTest.java L18
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/CreatorLabelsTest.java L3-7, L14, L47
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/ExecutorCommandWrapperTest.java L4-8
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java L13-20, L66-98 (+6 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskmasterEnvPropertiesTest.java L5
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterMinimalTest.java L5-8 (+4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterTest.java L105-124, L137-142, L631-648 (+12 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/SingleTaskStrategyTest.java L5-10
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/TaskBuilderTest.java L3-5, L16-22
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/TaskListStrategyTest.java L4-6, L11, L104-107
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/TaskTest.java L5, L7 (removed lines), L13
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperHttpTest.java L39-48 (+4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperTest.java L159-170, L277-303, L680-707 (+12 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/api/ServiceInfoApiControllerTest.java L3-30 (4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApiControllerTest.java L5-64 (4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/model/TaskViewTest.java L5
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/model/Tes11FieldsTest.java L3-11, L163-166, L179
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/model/TesExecutorTest.java L3-6
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/model/TesFileTypeDefaultTest.java L3-6
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/model/TesInputTest.java L3-6
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/model/TesResourcesTest.java L3-8, L53-57 (+2 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/ServiceInfoServiceTest.java L16-20, L31-34 (+5 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/trs/TrsToolClientTest.java L4-9, L37-50 (+4 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/trs/TrsToolClientTimeoutTest.java L8

Other changes

Files not grouped.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ServiceClientAuthIT.java L25-28, L69-91 (+5 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5e23790) to head (14fb18a).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #194   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           53        53           
  Lines         2260      2257    -3     
  Branches       255       254    -1     
=========================================
- Hits          2260      2257    -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

uniqueg and others added 2 commits November 16, 2026 05:22
@uniqueg
uniqueg marked this pull request as ready for review November 16, 2026 04:31
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 14fb18a

#167 test: move the tests to JUnit 5 · 6 of 6 met

# Requirement Status Notes
1 Move the unit and integration tests to JUnit Jupiter. ✅ Met The tests use Jupiter annotations and APIs, with Jupiter extensions replacing the JUnit 4 runners and rules.
2 Read CONFIGMAP, CONFIGMAPNAMESPACE and CONFIGMAPKEY through an injectable lookup or Spring properties, retaining the environment variables. ✅ Met KubernetesObjectsSupplier reads the settings through Spring Environment, and the tests configure it with MockEnvironment.
3 Drop JUnit 4, the vintage engine, system-rules and Surefire's --add-opens. ✅ Met The POM removes the vintage and system-rules dependencies and the module-opening arguments; no JUnit 4 dependencies or imports remain in the checked build and sources.
4 Update the development documentation. ✅ Met docs/development.md now documents the Jupiter setup and testing conventions.
5 Keep the same number of tests. ✅ Met The PR reports the same count per test class as dev; the migration preserves the parameterized cases and adds a ConfigMap settings test.
6 Do not lower coverage. ✅ Met The PR reports that the JaCoCo coverage check passes at 100% lines and branches.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserInfoTokenIntrospectorTest.java" line_range="159-160" />
<code_context>
+    static void mockUngroupedTaskKubernetesResponses(
+            WireMockExtension mockKubernetes, String userId) {
         mockTaskKubernetesResponses(mockKubernetes, taskmaster(null, userId));
     }

     /** Lets task-123 be a task of the user {@code userId} for the group {@code group} */
</code_context>
<issue_to_address>
**Refused-response test flakes**

When another local process binds the released port and serves valid user-info JSON, `introspector.introspect` accepts the response, so `refused()`'s `assertThrows` fails.

Test refusal with a deterministic approach that does not depend on a released port remaining unused.
</issue_to_address>

### Comment 2
<location path="src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java" line_range="72" />
<code_context>
+        environment.setProperty("CONFIGMAP", "security");
+        environment.setProperty("CONFIGMAPNAMESPACE", "config");
+        environment.setProperty("CONFIGMAPKEY", "executors");
         configMap("security", "config", new V1ConfigMap().putDataItem("executors", "{}"));

         assertThat(securityContext()).isEqualTo(new V1PodSecurityContext());
</code_context>
<issue_to_address>
**Custom key regressions pass**

When the supplier ignores `CONFIGMAPKEY` and the ConfigMap has no `securityContext` key, `emptySecurityContext` (line 74) and `configMapWithoutTheKey` (line 85) both expect an empty context, which is also returned if the supplier ignores `CONFIGMAPKEY` and looks for an absent default key, so the configured-key lookup regression passes.

Make a test with a nonempty value under the configured non-default key and assert the resulting security context.

Also at `src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java:82`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and spring’s Environment can resolve CONFIGMAP and its namespace/key from property sources beyond process environment variables, potentially selecting a different ConfigMap and applying unintended security settings to executor pods. Reverting changes future startups, but cannot undo effects of jobs already launched with that pod security context.

Blocking findings: src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserInfoTokenIntrospectorTest.java:160, src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java:72


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

- the unreachable user info endpoint is a port that a bound,
  non-listening socket holds during the call, instead of a port that
  was free a moment ago and that another process could take
- a test of a custom ConfigMap namespace and key with a non-empty
  security context, so that a supplier that ignored CONFIGMAPKEY would
  fail it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit bf9011c into dev Nov 16, 2026
34 checks passed
@uniqueg
uniqueg deleted the test/167-junit-5 branch November 16, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: move the tests to JUnit 5

1 participant