optimize: optimize common module#7721
Conversation
YoWuwuuuw
left a comment
There was a problem hiding this comment.
PR Changes requires registration.
common/src/test/java/org/apache/seata/common/util/CollectionUtilsTest.java
Outdated
Show resolved
Hide resolved
common/src/test/java/org/apache/seata/common/util/NetAddressValidatorUtilTest.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| @EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}) |
There was a problem hiding this comment.
Why this test is limited to Java 8 and Java 11, and CI builds fail.
Error: Tests run: 28, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.056 s <<< FAILURE! - in org.apache.seata.common.util.ReflectionUtilTest
Error: org.apache.seata.common.util.ReflectionUtilTest.testModifyStaticFinalFieldEnhanced Time elapsed: 0.012 s <<< FAILURE!
There was a problem hiding this comment.
The higher version of jdk does not allow the reflection of static final fields. This test case has been temporarily removed for now.
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the common module by significantly improving test coverage and adding documentation to utility classes. The main focus is on adding comprehensive test cases for existing functionality and improving code maintainability through better comments and documentation.
Key Changes
- Added extensive test coverage for utility classes (UUIDGenerator, StringUtils, SizeUtil, ReflectionUtil, NumberUtils, NetUtil, etc.)
- Replaced deprecated
Class.newInstance()withgetDeclaredConstructor().newInstance()in BeanUtils and EnhancedServiceLoader - Added JavaDoc documentation to utility classes (ConfigTools, CycleDependencyHandler, IOUtil, LambdaUtils, etc.)
- Enhanced error handling by changing silent exception swallowing to logging in IOUtil
Reviewed Changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/test/java/.../UUIDGeneratorTest.java | Added tests for UUID generation validation, multiple UUID uniqueness, and init parameter validation |
| common/src/test/java/.../StringUtilsTest.java | Added duplicate test methods for hasLength and hasText (already covered by existing tests) |
| common/src/test/java/.../SizeUtilTest.java | Added comprehensive tests for size parsing with valid/invalid inputs and boundary conditions |
| common/src/test/java/.../ReflectionUtilTest.java | Added enhanced tests for reflection operations including field/method access and error cases |
| common/src/test/java/.../CollectionUtilsTest.java | Added extensive tests for collection utilities with potential test correctness issues |
| common/src/main/java/.../BeanUtils.java | Replaced deprecated newInstance() with getDeclaredConstructor().newInstance() |
| common/src/main/java/.../IOUtil.java | Changed exception handling from silent ignore to warning logs |
| common/src/main/java/.../ConfigTools.java | Added comprehensive JavaDoc documentation for all public methods |
| common/src/main/java/.../CycleDependencyHandler.java | Added JavaDoc and improved null safety in containsObject method |
| common/src/main/java/.../EnhancedServiceLoader.java | Replaced deprecated newInstance() and added cached CLASS_LOADER field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .containsEntry("", "value2") | ||
| .containsEntry("key3", "value3") | ||
| .hasSize(2); |
There was a problem hiding this comment.
The test assertion on line 539 is incorrect. Looking at the decode logic, when parsing "key1=&=value2", the entry "key1=" will split into ["key1", ""], and the entry "=value2" will split into ["", "value2"]. However, the test expects only 2 entries with keys "" and "key3", which would mean "key1" is missing. The actual result should have 3 entries: ("key1", ""), ("", "value2"), and ("key3", "value3").
| .containsEntry("", "value2") | |
| .containsEntry("key3", "value3") | |
| .hasSize(2); | |
| .containsEntry("key1", "") | |
| .containsEntry("", "value2") | |
| .containsEntry("key3", "value3") | |
| .hasSize(3); |
There was a problem hiding this comment.
key is null or empty, will ignore.
common/src/test/java/org/apache/seata/common/util/CollectionUtilsTest.java
Outdated
Show resolved
Hide resolved
common/src/test/java/org/apache/seata/common/util/ReflectionUtilTest.java
Show resolved
Hide resolved
…ilsTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 2.x #7721 +/- ##
============================================
+ Coverage 69.03% 69.23% +0.19%
Complexity 994 994
============================================
Files 1322 1322
Lines 50167 50173 +6
Branches 5932 5931 -1
============================================
+ Hits 34635 34735 +100
+ Misses 12590 12526 -64
+ Partials 2942 2912 -30
🚀 New features to boost your workflow:
|
|
LGTM |
* optimize: optimize common module * format * fix review * fix review * Update common/src/test/java/org/apache/seata/common/util/CollectionUtilsTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Jiangke Wu <xingfudeshi@gmail.com> Co-authored-by: YoWuwuuuw <2216348784@qq.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ⅰ. Describe what this PR did
optimize common module
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews