Skip to content

Replace OsDetector and OS assumptions with JUnit 5 @EnabledOnOs #546

@redcatbear

Description

@redcatbear

Situation

The project currently uses a custom `OsDetector` utility (and an underlying `OsCheck` class) located in the `testutil` module to handle OS-specific test execution. This is typically done using methods like `OsDetector.assumeRunningOnWindows()` or `OsDetector.assumeRunningOnUnix()` inside test methods.

JUnit 5 provides a standard way to handle this via the `@EnabledOnOs` and `@DisabledOnOs` annotations. Using these standard annotations improves code readability, follows JUnit best practices, and allows for removing custom infrastructure code.

Implementation Hints

  1. Refactor Tests:
    • Replace calls to `OsDetector.assumeRunningOnWindows()` with `@EnabledOnOs(OS.WINDOWS)` at the method or class level.
    • Replace calls to `OsDetector.assumeRunningOnUnix()` with `@EnabledOnOs({OS.LINUX, OS.MAC})` or similar, depending on the test requirements.
    • Update tests in:
      • `core/src/test/java/org/itsallcode/openfasttrace/core/importer/TestImporterService.java`
      • `core/src/test/java/org/itsallcode/openfasttrace/core/importer/tag/config/DescribedPathMatcherTest.java`
      • `reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestOriginLinkFormatter.java`
      • `product/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReportCssInlining.java`
  2. Remove Utility Classes:
    • Once all references are removed, delete `org.itsallcode.openfasttrace.testutil.OsDetector` and `org.itsallcode.openfasttrace.testutil.OsCheck`.
    • Check for any other usages of `OsCheck` in production code.
  3. Update Dependencies:
    • Ensure `junit-jupiter-api` is available (it is already used across the project).

Acceptance Criteria

  1. `OsDetector` and `OsCheck` classes are removed from the codebase.
  2. All tests that previously used `OsDetector` now use `@EnabledOnOs` or other JUnit 5 execution conditions.
  3. The build passes on all target operating systems (Windows, Linux, macOS) in CI.
  4. `mvn verify` completes successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactoringCode improvement without behavior change
    No fields configured for Refactoring.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions