Skip to content

Improve test cases with better assertions and add tests for non-exist… #132

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

piomin
Copy link
Owner

@piomin piomin commented May 10, 2025

…ent entities

Summary by CodeRabbit

  • Tests
    • Improved test coverage for account, customer, and product services by adding new tests for non-existent entries.
    • Enhanced existing tests with clearer assertion messages and additional checks for key fields.
    • Adjusted test execution order to ensure consistent and logical test sequencing.
    • Reactivated and improved customer account association test for more comprehensive validation.

Copy link
Contributor

coderabbitai bot commented May 10, 2025

Walkthrough

Test classes across the account, customer, and product services were updated to consolidate assertion imports, enhance assertion clarity with messages, verify additional fields, and ensure sequential test execution with updated order annotations. New negative test cases were added to check repository behavior when querying non-existent entities.

Changes

File(s) Change Summary
.../account/repository/AccountRepositoryTest.java Consolidated assertion imports, added assertion messages, verified account number in assertions, updated test order, and added testFindNonExistentAccount for negative lookup.
.../customer/CustomerControllerTests.java Consolidated assertion imports, enabled and annotated findCustomerWithAccounts test, added and enhanced assertions for customer creation and retrieval.
.../customer/CustomerRepositoryTests.java Consolidated assertion imports, added assertion messages, verified customer name and PESEL, updated test order, and added testFindNonExistentCustomer for negative lookup.
.../product/ProductRepositoryTests.java Consolidated assertion imports, added assertion messages, verified account ID, updated test order, and added testFindNonExistentProduct for negative lookup.

Sequence Diagram(s)

sequenceDiagram
    participant TestClass
    participant Repository

    TestClass->>Repository: save(entity)
    Repository-->>TestClass: entity with ID

    TestClass->>Repository: findById(existingId)
    Repository-->>TestClass: Optional.of(entity)

    TestClass->>Repository: findById(nonExistentId)
    Repository-->>TestClass: Optional.empty

    TestClass->>Repository: findByField(fieldValue)
    Repository-->>TestClass: Optional.of(entity) or Optional.empty

    Note over TestClass: Assertions check entity fields and presence
Loading

Poem

In the warren of tests, we hop and we check,
With messages clear, no assertion a wreck.
If you’re missing, dear entity, we’ll surely detect—
For coverage and order, our carrots are decked!
🥕
— A rabbit, with a keen nose for bugs

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b5de357 and 9b9e821.

📒 Files selected for processing (4)
  • account-service/src/test/java/pl/piomin/microservices/advanced/account/repository/AccountRepositoryTest.java (2 hunks)
  • customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerControllerTests.java (2 hunks)
  • customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerRepositoryTests.java (2 hunks)
  • product-service/src/test/java/pl/piomin/microservices/advanced/product/ProductRepositoryTests.java (2 hunks)
🔇 Additional comments (23)
account-service/src/test/java/pl/piomin/microservices/advanced/account/repository/AccountRepositoryTest.java (6)

18-18: Good use of static import for assertions.

Using a wildcard static import for all JUnit assertions simplifies the code and makes the test methods cleaner.


47-48: Great addition of assertion messages.

Adding descriptive messages to assertions improves test failure diagnostics by clearly explaining what was expected. This makes debugging much easier when tests fail.


56-57: Improved verification with additional property check.

The enhanced assertions now verify both the presence of the account and the correctness of its number property. This ensures that not only is an account found, but it's the right one.


61-61: Proper test execution order.

Changing the order annotation to maintain sequential numbering (from 2 to 3) helps ensure tests run in the intended sequence, which is important when tests have dependencies.


64-65: Enhanced assertions with property verification.

Adding messages to assertions and verifying the account number matches the expected value improves test quality by ensuring data integrity.


68-73: Excellent addition of negative test case.

Adding a test for non-existent entities improves test coverage by verifying the repository correctly handles cases where data doesn't exist. This aligns perfectly with the PR objectives.

product-service/src/test/java/pl/piomin/microservices/advanced/product/ProductRepositoryTests.java (6)

21-21: Consistent approach with static imports.

Using a wildcard static import for assertions maintains consistency with other test classes and improves code readability.


52-53: Clear assertion messages for better diagnostics.

Adding descriptive messages to assertions improves failure diagnostics by providing clear explanations of what was expected.


60-62: Improved variable naming and property verification.

Renaming the Optional variable to "optProd" enhances readability, and verifying the accountId property ensures data integrity beyond just checking for presence.


66-66: Consistent test execution order.

Changing the test order annotation from 2 to 3 maintains a proper sequence of test execution, ensuring consistency across test classes.


69-70: Enhanced assertions with meaningful messages.

Adding descriptive messages and verifying the product's accountId matches the expected value improves test quality and readability.


73-78: Valuable negative test case.

Adding a test for non-existent entities verifies the repository correctly handles cases where a product doesn't exist, improving test coverage for edge cases.

customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerControllerTests.java (5)

28-28: Consistent static import pattern.

Using the wildcard static import for assertions maintains consistency with other test classes and improves code readability.


61-63: Improved test validation and setup.

Adding assertions to verify the customer and its ID after creation, and storing the ID for subsequent tests, improves both test quality and test data management.


66-68: Excellent enablement of previously commented test.

Enabling the findCustomerWithAccounts test method increases test coverage by validating the integration with the account service. The proper order annotation ensures it runs after the customer is created.


75-76: Enhanced verification of customer properties.

Adding assertions to verify both presence and PESEL value of the customer ensures the correct customer is retrieved by the API.


79-80: Comprehensive integration test.

Verifying that the customer exists and has associated accounts effectively tests the integration with the account service (mocked via Hoverfly), ensuring the association between services works correctly.

customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerRepositoryTests.java (6)

20-20: Consistent static import approach.

Using the wildcard static import for assertions maintains consistency across all test classes in the project.


49-50: Clear assertion messages for better diagnostics.

Adding descriptive messages to assertions improves test failure diagnostics by clearly explaining what was expected.


58-59: Valuable property verification.

Adding an assertion to verify the customer's name matches the expected value improves test quality by ensuring data integrity beyond just checking for presence.


63-63: Consistent test execution order.

Changing the test order annotation from 2 to 3 maintains consistency with the ordering pattern used in other repository test classes.


66-67: Enhanced assertions with meaningful messages.

Adding descriptive messages and verifying the customer's PESEL value improves test quality and maintainability.


70-75: Important negative test case.

Adding a test for non-existent customers verifies the repository correctly handles cases where a customer doesn't exist, completing the test coverage for repository behavior.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

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.

1 participant