Skip to content

Add tests for Sets utility class#3771

Merged
TimvdLippe merged 2 commits intomockito:mainfrom
thswlsqls:test/add-sets-utility-tests
Dec 16, 2025
Merged

Add tests for Sets utility class#3771
TimvdLippe merged 2 commits intomockito:mainfrom
thswlsqls:test/add-sets-utility-tests

Conversation

@thswlsqls
Copy link
Copy Markdown
Contributor

Summary

Add comprehensive test coverage for Sets utility class which provides factory methods for creating mock-safe hash sets and regular sets. This improves code coverage and ensures correct behavior of set creation methods.

Changes

  • Added SetsTest class with 17 test methods covering all three static methods:
    • newMockSafeHashSet(Iterable<Object>) - 4 tests
    • newMockSafeHashSet(Object...) - 3 tests
    • newSet(T...) - 10 tests
  • Test scenarios include:
    • Mock objects handling
    • Regular objects handling
    • Empty collections
    • Null handling (with proper AssertJ type casting)
    • Duplicate elements
    • Order preservation (LinkedHashSet behavior)
    • Error cases (null array parameter)
    • Set operations (add, remove)

Note: AssertJ's contains() and containsExactly() methods require explicit type casting when checking for null values (e.g., contains((Object) null)) to avoid NullPointerException caused by varargs array creation.

Testing

All tests pass:

./gradlew :mockito-core:test --tests "org.mockito.internal.util.collections.SetsTest"

Add comprehensive test coverage for Sets utility class which provides
factory methods for creating mock-safe hash sets and regular sets.
Tests cover all three static methods with various scenarios including
mock objects, regular objects, edge cases, and error handling.

- Test newMockSafeHashSet(Iterable<Object>) with various scenarios
- Test newMockSafeHashSet(Object...) with various scenarios
- Test newSet(T...) with various types
- Test edge cases (empty collections, null handling, duplicates)
- Test set operations (add, remove)
- Fix AssertJ null handling by using explicit type casting to avoid NullPointerException
Copy link
Copy Markdown
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

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

Thanks for these! They make sense to me. Only nit is about the comments.


Set<Object> result = Sets.newMockSafeHashSet(mock, mock);

// Mock 객체는 동일한 인스턴스이므로 Set에는 하나만 포함
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please either remove these comments or use English

Copy link
Copy Markdown
Contributor Author

@thswlsqls thswlsqls Dec 16, 2025

Choose a reason for hiding this comment

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

@TimvdLippe Thank you for the feedback! I've addressed your comment by translating all Korean comments to English and added class-level Javadoc for better documentation. The changes have been committed.

All comments are now in English:

  • Translated 3 Korean comments to English
  • Added class-level Javadoc for SetsTest
  • Added 2 explanatory comments for AssertJ null handling

Please let me know if there's anything else that needs to be adjusted.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.48%. Comparing base (09d2230) to head (3ba3c5e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3771      +/-   ##
============================================
+ Coverage     86.46%   86.48%   +0.02%     
- Complexity     2988     2989       +1     
============================================
  Files           341      341              
  Lines          9041     9041              
  Branches       1113     1113              
============================================
+ Hits           7817     7819       +2     
+ Misses          942      941       -1     
+ Partials        282      281       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Replace Korean comments with English and add missing documentation
to improve code readability and maintainability.

- Add class-level Javadoc for SetsTest
- Translate Korean comments to English (3 comments)
- Add explanatory comments for AssertJ null handling (2 comments)
- Improve code documentation consistency
@TimvdLippe TimvdLippe merged commit 9e5d449 into mockito:main Dec 16, 2025
19 checks passed
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