Skip to content

Add test case for JUnit Jupiter @Nested class - #773#833

Open
mskacelik wants to merge 1 commit intoarquillian:mainfrom
mskacelik:test-773
Open

Add test case for JUnit Jupiter @Nested class - #773#833
mskacelik wants to merge 1 commit intoarquillian:mainfrom
mskacelik:test-773

Conversation

@mskacelik
Copy link
Copy Markdown

@mskacelik mskacelik commented Apr 27, 2026

Introduced a new test class for the @Nested test. Tried to reuse the FileWriterExtension pattern (for the persistent state between client and server/container) but had to make some changes since the FileWriterExtension wasn't very flexible for other test cases.

Summary by Sourcery

Add support in the lifecycle test infrastructure to assert configurable expected traces and introduce coverage for JUnit Jupiter nested test classes.

Enhancements:

  • Make FileWriterExtension reusable across multiple lifecycle tests by parameterizing expected traces via an annotation and scoping its global store key per test class.
  • Extract file reading logic in FileWriterExtension and centralize temporary file naming using a shared constant.
  • Introduce the ExpectedTrace annotation to declare the expected lifecycle event sequence on a per-test-class basis.

Tests:

  • Annotate the existing LifecycleMethodsTest with ExpectedTrace to validate its lifecycle event sequence declaratively.
  • Add a new NestedClassTest (currently disabled) to verify lifecycle behavior and event ordering for JUnit Jupiter @nested test classes.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 27, 2026

Reviewer's Guide

Adds a new JUnit 5 @nested class Arquillian lifecycle test and generalizes FileWriterExtension so expected lifecycle traces are provided via a new @ExpectedTrace annotation, allowing reuse across multiple tests including nested-class scenarios.

File-Level Changes

Change Details Files
Generalize FileWriterExtension to support multiple test classes and configurable expected lifecycle traces.
  • Introduce ARQUILLIAN_LIFECYCLE_TEST constant and use it for temp directory naming.
  • Track the current test class in beforeAll and skip setup when the class is not annotated with @ExpectedTrace to support @nested usage.
  • Change the global store key to be unique per test class to avoid cross-test interference.
  • Refactor file reading logic into a reusable readFromFile() helper with a larger buffer and safe empty-content handling.
  • Replace hard-coded expected trace assertion with one that reads the value from the @ExpectedTrace annotation on the test class.
integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/lifecycle/FileWriterExtension.java
Annotate existing LifecycleMethodsTest with @ExpectedTrace and include the new annotation in the deployment archive.
  • Add @ExpectedTrace with the original expected lifecycle trace string to LifecycleMethodsTest.
  • Ensure ExpectedTrace is packaged in the ShrinkWrap JavaArchive so it is available in-container.
  • Reorder static imports for readability (no behavioral change).
integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/lifecycle/LifecycleMethodsTest.java
Introduce a new disabled NestedClassTest that verifies Arquillian + JUnit 5 lifecycle behavior with @nested classes using FileWriterExtension and @ExpectedTrace.
  • Create NestedClassTest with Arquillian and FileWriterExtension extensions, using @TestClassOrder and @TestMethodOrder to guarantee execution ordering.
  • Define outer-level lifecycle methods that append markers to the shared file and assert client/server execution where applicable.
  • Define an @nested InnerTest class with its own @BeforeEach/@AfterEach and test methods appending additional markers and asserting server-side execution.
  • Set an @ExpectedTrace value describing the full expected call sequence across outer and nested tests.
  • Configure the deployment to include FileWriterExtension, ExpectedTrace, the temp file asset, and beans.xml.
integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/lifecycle/NestedClassTest.java
Add ExpectedTrace annotation to parameterize the expected lifecycle trace string used by FileWriterExtension.
  • Introduce a new @interface ExpectedTrace that holds a String value representing the expected lifecycle trace.
  • Use ExpectedTrace as a marker for which test classes FileWriterExtension should manage and validate, enabling reuse for different scenarios.
integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/lifecycle/ExpectedTrace.java

Possibly linked issues


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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In FileWriterExtension.readFromFile(), relying on a fixed 10,000-char buffer and stripping the last character assumes a trailing separator and bounded file size; consider using Files.readString(getTmpFilePath()) and trimming as needed to make the read logic simpler and more robust.
  • FileWriterExtension keeps TMP_FILE_PATH as a static mutable field while also keying the extension instance by test class; this can lead to interference between tests (especially if run in parallel), so it would be safer to make the path instance- or class-specific rather than shared static state.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In FileWriterExtension.readFromFile(), relying on a fixed 10,000-char buffer and stripping the last character assumes a trailing separator and bounded file size; consider using Files.readString(getTmpFilePath()) and trimming as needed to make the read logic simpler and more robust.
- FileWriterExtension keeps TMP_FILE_PATH as a static mutable field while also keying the extension instance by test class; this can lead to interference between tests (especially if run in parallel), so it would be safer to make the path instance- or class-specific rather than shared static state.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rhusar
Copy link
Copy Markdown
Member

rhusar commented Apr 28, 2026

Approving workflows to run now.

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.

2 participants