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

Introduce missing assertEquals(long, Long, String) overload #3199

Conversation

Stephan202
Copy link
Contributor

@Stephan202 Stephan202 commented Dec 27, 2024

This reinstates a method that was introduced in
80e02ff but accidentally replaced in
89dc584.

Summary by CodeRabbit

  • New Features

    • Introduced a new assertion method to compare primitive long values with Long objects.
  • Tests

    • Enhanced test coverage for boxed and unboxed long comparisons.

This reinstates a method that was introduced in
80e02ff but accidentally replaced in
89dc584.
Copy link

coderabbitai bot commented Dec 27, 2024

Walkthrough

The pull request introduces a new method assertEquals(long actual, Long expected, String message) in the TestNG Assert class. This method allows for equality comparison between a primitive long and its corresponding Long wrapper object. A corresponding test method is added to validate this new assertion functionality, enhancing the type comparison capabilities of the TestNG assertion framework.

Changes

File Change Summary
testng-asserts/src/main/java/org/testng/Assert.java Added new assertEquals method to support comparison between primitive long and Long wrapper
testng-asserts/src/test/java/test/asserttests/AssertTest.java Updated assertEqualsBoxedUnboxedLong() test method with additional assertion for Long and primitive long comparison

Poem

🐰 In the realm of testing's delight,
A new assertion takes its flight!
Long meets Long, boxed and free,
Comparing types with harmony 🧪
TestNG's magic, precise and bright!

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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
Contributor Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Some context. Found while working on PicnicSupermarket/error-prone-support#1483.

@@ -51,6 +51,7 @@ public void assertEqualsBoxedUnboxedLong() {
assertEquals(a, b);
assertEquals(a, b, "");
assertEquals(b, a);
assertEquals(b, a, "");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the added method, this statement causes a compilation failure:

Execution failed for task ':testng-asserts:compileTestJava'.
> Compilation failed; see the compiler output below.
  /tmp/testng/testng-asserts/src/test/java/test/asserttests/AssertTest.java:54: error: reference to assertEquals is ambiguous
      assertEquals(b, a, "");
      ^
    both method assertEquals(double,double,String) in Assert and method assertEquals(Object,Object,String) in Assert match
  1 error

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: 0

🧹 Nitpick comments (1)
testng-asserts/src/test/java/test/asserttests/AssertTest.java (1)

54-55: Enhance test clarity with dedicated test method or inline comment.

Two additional assertions have been introduced (assertEquals(b, a, "") and assertEquals(Long.valueOf(b), a, "")). Although these assert the same logical equality (since b is the primitive equivalent of Long.valueOf(b)), it may be beneficial to clarify this subtle difference. This could be done by:

  • Creating a dedicated test method referencing "primitive vs. wrapped long" equivalence, or
  • Adding an inline comment describing the reason for double coverage with both the primitive and the wrapper type.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db6c5a9 and e4a6944.

📒 Files selected for processing (2)
  • testng-asserts/src/main/java/org/testng/Assert.java (1 hunks)
  • testng-asserts/src/test/java/test/asserttests/AssertTest.java (1 hunks)
🔇 Additional comments (1)
testng-asserts/src/main/java/org/testng/Assert.java (1)

971-982: New overload aligns with existing design—but verify usage.

The newly added method assertEquals(long actual, Long expected, String message) is consistent with the existing overloads for other numeric types. Be sure to confirm that all relevant call sites are either added or updated (e.g. user code calling assertEquals with a long, Long signature).

✅ Verification successful

Let me gather more information about the usage patterns.


Implementation and usage patterns are consistent

The verification shows that:

  1. The new assertEquals(long actual, Long expected, String message) overload is properly implemented with a corresponding no-message variant
  2. The implementation correctly boxes the primitive long to Long before delegation
  3. Existing test cases in AssertionsTestSample.groovy demonstrate proper usage with both message and no-message variants, though they use explicitly boxed values

The implementation aligns with TestNG's assertion method patterns and has test coverage. No issues requiring updates were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage references of the newly added assertEquals(long, Long, String).

rg -A 5 $'assertEquals\\(\\s*[^,]+,\\s*[^,]+,\\s*\"' | grep 'long.*Long'

Length of output: 384


Script:

#!/bin/bash
# Search for assertEquals with long and Long parameters in test files
rg -t java -t groovy "assertEquals.*\(.*long.*Long.*\)" -B 1 -A 1

# Search for potential call sites that might need updating
ast-grep --pattern 'assertEquals($actual, $expected, $_)'

Length of output: 1238

@krmahadevan krmahadevan merged commit 078c1e3 into testng-team:master Dec 29, 2024
8 of 10 checks passed
@Stephan202 Stephan202 deleted the sschroevers/resolve-ambigious-reference branch December 29, 2024 09:16
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.

3 participants