Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honour inheritance when parsing listener factories #3096

Merged
merged 1 commit into from Mar 19, 2024

Conversation

krmahadevan
Copy link
Member

@krmahadevan krmahadevan commented Mar 19, 2024

Closes #3095

Fixes #3095 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

Root cause: TestNG was enhanced such that the @Listeners annotation was inheritable via the PR #3002

Summary by CodeRabbit

  • Bug Fixes
    • Addressed issues with test execution behavior, including test class inheritance and method interception.
  • New Features
    • Improved handling and uniqueness of listener annotations in test execution.
    • Enhanced management of listener factories for more effective test listener integration.
  • Refactor
    • Streamlined test listener logic for better efficiency and clarity.
    • Introduced new test classes and methods for improved testing of listener inheritance and factory functionality.
  • Tests
    • Added new tests to ensure correct handling of listener inheritance and listener factory behavior.

Copy link

coderabbitai bot commented Mar 19, 2024

Walkthrough

The recent changes focus on enhancing test execution behavior, addressing issues with test class inheritance, method interception, listener control, and instance management during method invocation. Additionally, improvements in listener handling, including the use of Optional, ensure unique listener classes and more effective management of listener factories, complemented by comprehensive testing and refactoring efforts.

Changes

Files Change Summary
CHANGES.txt Fixed issues with test execution, class inheritance, method interception, listener inclusion at runtime, and instance return.
.../internal/TestListenerHelper.java, .../TestListenerHelperTest.java Streamlined listener handling using Optional, ensured unique listener classes, and managed listener factories more effectively. Refactored listener containers.
.../listeners/ListenerFactoryContainer.java, .../listeners/TestClassContainer.java, .../listeners/TestClassWithCompositeListener.java Introduced new classes for listener factories and test class containers. Updated import and annotation for better listener management.
.../test/listeners/ListenersTest.java, .../listeners/issue3095/ChildClassSample.java, .../listeners/issue3095/MyTestNgFactory.java, .../listeners/issue3095/SuperClassSample.java Added tests for listener inheritance and updated listener factory handling, addressing specific issue behaviors.

Assessment against linked issues

Objective Addressed Explanation
Handling ITestNGListenerFactory annotations on superclasses without crashing (#3095)
Correct instance return in @BeforeMethod, @AfterMethod, and @AfterClass in listeners (#3082)
Fix NullPointerException in ConcurrentHashMap.putVal during test execution after upgrading to version 7.9.0 (#3030) The changes do not directly address the NullPointerException issue mentioned in issue #3030. This might require a specific fix not covered in the summarized changes.

Related issues

  • Issue testng-team/testng#3082 could be linked to this PR as the changes include improvements in listener handling and instance management during test execution phases, which align with the objectives of ensuring correct instance return.

🐇✨
In the realm of code, where tests and bugs collide,
A rabbit hopped in, with changes wide.
With a flick and a hop, bugs begin to hide,
As tests run smooth, in a seamless glide.
"To better code," the rabbit cried,
"Where listeners and instances, in harmony, abide."
✨🐇

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 554cfa6 and 8900462.
Files selected for processing (10)
  • CHANGES.txt (1 hunks)
  • testng-core/src/main/java/org/testng/internal/TestListenerHelper.java (4 hunks)
  • testng-core/src/test/java/org/testng/internal/TestListenerHelperTest.java (3 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/ListenerFactoryContainer.java (1 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassContainer.java (1 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassWithCompositeListener.java (1 hunks)
  • testng-core/src/test/java/test/listeners/ListenersTest.java (2 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/ChildClassSample.java (1 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/MyTestNgFactory.java (1 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/SuperClassSample.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • testng-core/src/test/java/org/testng/internal/listeners/ListenerFactoryContainer.java
Additional comments: 7
testng-core/src/test/java/test/listeners/issue3095/SuperClassSample.java (1)
  • 1-6: The usage of @Listeners to specify MyTestNgFactory as a listener factory is correctly implemented.
testng-core/src/test/java/test/listeners/issue3095/ChildClassSample.java (1)
  • 1-8: The inheritance of @Listeners from SuperClassSample and the definition of a test method are correctly implemented.
testng-core/src/test/java/org/testng/internal/listeners/TestClassWithCompositeListener.java (1)
  • 3-9: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-6]

The update to use ListenerFactoryContainer.DummyListenerFactory in the @Listeners annotation is correctly implemented and aligns with the refactor to encapsulate listener factories.

testng-core/src/test/java/org/testng/internal/TestListenerHelperTest.java (1)
  • 45-69: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-88]

The tests in TestListenerHelperTest are well-structured and cover the new functionality introduced in the PR. It would be beneficial to add more detailed comments to the test methods, especially testFindAllListenersDuplicateListenerFactories, to explain the scenarios being tested and the expected outcomes.

+  // Test to verify that TestNG can handle duplicate listener factories without issues.
   @Test(description = "GITHUB-3095")
   public void testFindAllListenersDuplicateListenerFactories() {
testng-core/src/main/java/org/testng/internal/TestListenerHelper.java (1)
  • 176-212: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-209]

The use of Optional and the updated logic in ListenerHolder for handling listener annotations and factories are correctly implemented. However, refining the exception message when multiple listener factories are found would enhance clarity and provide more context.

-        throw new TestNGException(
-            "Found more than one class implementing ITestNGListenerFactory:"
-                + c
-                + " and "
-                + listenerFactoryClass);
+        throw new TestNGException(String.format(
+            "Found more than one class implementing ITestNGListenerFactory: %s and %s. "
+            + "Please ensure that only one ITestNGListenerFactory is specified.",
+            c.getName(), listenerFactoryClass.getName()));
CHANGES.txt (2)
  • 3-3: The change log entry for GITHUB-3095 is clear and directly addresses the issue described in the PR objectives, specifically the handling of ITestNGListenerFactory annotations on superclasses and preventing crashes due to multiple implementations.
  • 1-6: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-22]

All listed changes in the version 7.10.0 log are consistent with the PR objectives and the AI-generated summary, indicating a comprehensive fix for the identified bug and related issues. The documentation of fixes and new features is clear, contributing to the maintainability and usability of the TestNG framework.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 554cfa6 and 4dc09dc.
Files selected for processing (10)
  • CHANGES.txt (1 hunks)
  • testng-core/src/main/java/org/testng/internal/TestListenerHelper.java (4 hunks)
  • testng-core/src/test/java/org/testng/internal/TestListenerHelperTest.java (3 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/ListenerFactoryContainer.java (1 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassContainer.java (1 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassWithCompositeListener.java (1 hunks)
  • testng-core/src/test/java/test/listeners/ListenersTest.java (2 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/ChildClassSample.java (1 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/MyTestNgFactory.java (1 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/SuperClassSample.java (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • CHANGES.txt
  • testng-core/src/main/java/org/testng/internal/TestListenerHelper.java
  • testng-core/src/test/java/org/testng/internal/TestListenerHelperTest.java
  • testng-core/src/test/java/org/testng/internal/listeners/ListenerFactoryContainer.java
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassContainer.java
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassWithCompositeListener.java
  • testng-core/src/test/java/test/listeners/ListenersTest.java
  • testng-core/src/test/java/test/listeners/issue3095/ChildClassSample.java
  • testng-core/src/test/java/test/listeners/issue3095/MyTestNgFactory.java
  • testng-core/src/test/java/test/listeners/issue3095/SuperClassSample.java

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 554cfa6 and 55b08e6.
Files selected for processing (10)
  • CHANGES.txt (1 hunks)
  • testng-core/src/main/java/org/testng/internal/TestListenerHelper.java (4 hunks)
  • testng-core/src/test/java/org/testng/internal/TestListenerHelperTest.java (3 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/ListenerFactoryContainer.java (1 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassContainer.java (1 hunks)
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassWithCompositeListener.java (1 hunks)
  • testng-core/src/test/java/test/listeners/ListenersTest.java (2 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/ChildClassSample.java (1 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/MyTestNgFactory.java (1 hunks)
  • testng-core/src/test/java/test/listeners/issue3095/SuperClassSample.java (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • CHANGES.txt
  • testng-core/src/main/java/org/testng/internal/TestListenerHelper.java
  • testng-core/src/test/java/org/testng/internal/TestListenerHelperTest.java
  • testng-core/src/test/java/org/testng/internal/listeners/ListenerFactoryContainer.java
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassContainer.java
  • testng-core/src/test/java/org/testng/internal/listeners/TestClassWithCompositeListener.java
  • testng-core/src/test/java/test/listeners/ListenersTest.java
  • testng-core/src/test/java/test/listeners/issue3095/ChildClassSample.java
  • testng-core/src/test/java/test/listeners/issue3095/MyTestNgFactory.java
  • testng-core/src/test/java/test/listeners/issue3095/SuperClassSample.java

@krmahadevan krmahadevan merged commit 69dc232 into testng-team:master Mar 19, 2024
7 of 9 checks passed
@krmahadevan krmahadevan deleted the fix_3095 branch March 19, 2024 13:02
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.

Super class annotated with ITestNGListenerFactory makes derived test class throw TestNGException on execution
2 participants