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

Allow users to access factory method params info #3115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

krmahadevan
Copy link
Member

@krmahadevan krmahadevan commented Apr 23, 2024

Closes #3111

TestNG now exposes the IParameterInfo interface
Via which you can extract the following details
Pertaining to a factory powered test.

  • the index - which would match with what was Specified in the “indices” attribute of the “Factory” Annotation. If nothing was specified, then this
    Would be equal to a running count on the total instances.

  • current index - which represents a running count On the total instances.

  • The parameters of the factory method

  • The instance that was produced.

Fixes #3111 .

Did you remember to?

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

We encourage pull requests that:

  • Add new features to TestNG (or)
  • Fix bugs in TestNG

If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.

Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.

Summary by CodeRabbit

  • New Features
    • Introduced interfaces for handling factory methods and their parameters in tests, enhancing parameter retrieval and method sorting capabilities.
  • Refactor
    • Updated method calls and logic related to factory methods to utilize new interfaces, improving code efficiency and maintainability.
  • Deprecations
    • Deprecated certain functionalities in favor of newer, more efficient methods.
  • Bug Fixes
    • Fixed parameter retrieval logic in test configuration, ensuring accurate handling of test parameters.

Copy link

coderabbitai bot commented Apr 23, 2024

Walkthrough

The updates across various TestNG files primarily enhance the handling of factory methods and their parameters using the Optional class, deprecate old functionalities, and streamline instance management. This includes introducing new interfaces and updating existing ones to improve code clarity and maintainability.

Changes

File Path Change Summary
testng-core-api/src/main/java/org/testng/IFactoryMethod.java Introduced IFactoryMethod interface with getParameters() method returning parameters wrapped in Optional.
testng-core-api/src/main/java/org/testng/ITestClassInstance.java Introduced ITestClassInstance interface for retrieving factory method parameters.
testng-core-api/src/main/java/org/testng/ITestNGMethod.java Added getFactoryMethod() method returning an Optional<IFactoryMethod>.
testng-core-api/src/main/java/org/testng/internal/IParameterInfo.java Deprecated functionality and extended compatibility with new interfaces.
testng-core/src/main/java/org/testng/DependencyMap.java,
testng-core/src/main/java/org/testng/internal/BaseTestMethod.java,
testng-core/src/main/java/org/testng/internal/MethodSorting.java,
testng-core/src/test/java/test/configuration/issue2426/MyMethodListener.java,
testng-runner-api/src/main/java/org/testng/internal/TestResult.java
Refactored to utilize new interfaces and methods, enhancing parameter handling and instance management.

Assessment against linked issues

Objective Addressed Explanation
Replacement API for IClass.getInstanceHashCodes() and IClass.getInstances(boolean) (#3111) No direct replacement API for these methods has been introduced or modified in the changes listed.

Possibly related issues

🐇✨
A hop through the code, with care and glee,
Refactoring done, improvements we see!
Optional wraps, parameters align,
TestNG's new charm, in code does shine!
🌟📜🐾


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 43af2cf and f11c4fc.
Files selected for processing (20)
  • CHANGES.txt (1 hunks)
  • testng-core-api/src/main/java/org/testng/IFactoryMethod.java (1 hunks)
  • testng-core-api/src/main/java/org/testng/ITestClassInstance.java (1 hunks)
  • testng-core-api/src/main/java/org/testng/ITestNGMethod.java (2 hunks)
  • testng-core-api/src/main/java/org/testng/internal/IParameterInfo.java (1 hunks)
  • testng-core/src/main/java/org/testng/DependencyMap.java (2 hunks)
  • testng-core/src/main/java/org/testng/TestClass.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/BaseTestMethod.java (5 hunks)
  • testng-core/src/main/java/org/testng/internal/ClassImpl.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/FactoryMethod.java (4 hunks)
  • testng-core/src/main/java/org/testng/internal/MethodSorting.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/ParameterInfo.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java (3 hunks)
  • testng-core/src/test/java/test/configuration/issue2426/MyMethodListener.java (2 hunks)
  • testng-core/src/test/java/test/factory/FactoryIntegrationTest.java (4 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestSample.java (1 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithIndicesSample.java (1 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderSample.java (1 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample.java (1 hunks)
  • testng-runner-api/src/main/java/org/testng/internal/TestResult.java (2 hunks)
Files skipped from review as they are similar to previous changes (19)
  • CHANGES.txt
  • testng-core-api/src/main/java/org/testng/IFactoryMethod.java
  • testng-core-api/src/main/java/org/testng/ITestClassInstance.java
  • testng-core-api/src/main/java/org/testng/ITestNGMethod.java
  • testng-core-api/src/main/java/org/testng/internal/IParameterInfo.java
  • testng-core/src/main/java/org/testng/DependencyMap.java
  • testng-core/src/main/java/org/testng/TestClass.java
  • testng-core/src/main/java/org/testng/internal/BaseTestMethod.java
  • testng-core/src/main/java/org/testng/internal/ClassImpl.java
  • testng-core/src/main/java/org/testng/internal/FactoryMethod.java
  • testng-core/src/main/java/org/testng/internal/MethodSorting.java
  • testng-core/src/main/java/org/testng/internal/ParameterInfo.java
  • testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java
  • testng-core/src/test/java/test/configuration/issue2426/MyMethodListener.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestSample.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithIndicesSample.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderSample.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample.java
  • testng-runner-api/src/main/java/org/testng/internal/TestResult.java
Additional comments not posted (3)
testng-core/src/test/java/test/factory/FactoryIntegrationTest.java (3)

36-38: The updated error message correctly reflects the new requirements for factory methods. Good job on maintaining clarity in the test expectations.


62-63: The updated error message accurately reflects the new type requirements for factory methods. This change enhances the clarity and correctness of the test.


103-110: The data provider is correctly set up to supply the necessary test data for the ensureCurrentIndexWorksForFactoryPoweredTests method. Well done on maintaining clarity and correctness in the test setup.


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 testing code 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 testing code 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 testing code.
    • @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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 1

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.

Actionable comments posted: 1

Copy link
Member

@juherr juherr left a comment

Choose a reason for hiding this comment

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

It is working but I'm a bit confused as each time we want to change the API because it is complicated to fix after the release.

@krmahadevan krmahadevan requested a review from juherr April 24, 2024 05:25
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.

Actionable comments posted: 1

Closes testng-team#3111

TestNG now exposes the IParameterInfo interface 
Via which you can extract the following details
Pertaining to a factory powered test.

* the index - which would match with what was 
Specified in the “indices” attribute of the “Factory” 
Annotation. If nothing was specified, then this
Would be equal to a running count on the total instances.

* current index - which represents a running count
On the total instances.

* The parameters of the factory method

* The instance that was produced.
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.

Actionable comments posted: 1

new ITestListener() {
@Override
public void onTestSuccess(ITestResult result) {
params.add(result.getMethod().getFactoryMethodParamsInfo());
Copy link

Choose a reason for hiding this comment

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

The method getFactoryMethodParamsInfo() does not exist in the new API. You should use getFactoryMethod().flatMap(IFactoryMethod::getParameters) instead to align with the updated interfaces.

- params.add(result.getMethod().getFactoryMethodParamsInfo());
+ params.add(result.getMethod().getFactoryMethod().flatMap(IFactoryMethod::getParameters).orElse(null));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
params.add(result.getMethod().getFactoryMethodParamsInfo());
params.add(result.getMethod().getFactoryMethod().flatMap(IFactoryMethod::getParameters).orElse(null));

@krmahadevan
Copy link
Member Author

ping @juherr - Please let me know if there are any other comments that need to be addressed or if this can be merged

@juherr
Copy link
Member

juherr commented Apr 29, 2024

I'm working on it. I'm fighting against the issues of the legacy model.

@krmahadevan
Copy link
Member Author

I'm working on it. I'm fighting against the issues of the legacy model.

May the force be with you :) Will wait to hear back from you

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.

Replacement API for IClass.getInstanceHashCodes() and IClass.getInstances(boolean)
2 participants