YoWuwuuuw commented on code in PR #7721:
URL: https://github.com/apache/incubator-seata/pull/7721#discussion_r2485651417


##########
common/src/test/java/org/apache/seata/common/util/ReflectionUtilTest.java:
##########
@@ -203,6 +208,242 @@ public void testGetAnnotationValues() throws 
NoSuchMethodException, NoSuchFieldE
                         
this.getClass().getMethod("testGetAnnotationValues").getAnnotation(Test.class)));
     }
 
+    // Enhanced test cases
+
+    @Test
+    public void testGetClassByNameEnhanced() throws ClassNotFoundException {
+        // Test normal case
+        
assertThat(ReflectionUtil.getClassByName("java.lang.String")).isEqualTo(String.class);
+
+        // Test exception case
+        assertThatThrownBy(() -> 
ReflectionUtil.getClassByName("non.existent.Class"))
+                .isInstanceOf(ClassNotFoundException.class);
+    }
+
+    @Test
+    public void testIsClassPresentEnhanced() {
+        // Test existing class
+        assertThat(ReflectionUtil.isClassPresent("java.lang.String")).isTrue();
+
+        // Test non-existing class
+        
assertThat(ReflectionUtil.isClassPresent("non.existent.Class")).isFalse();
+    }
+
+    @Test
+    public void testGetWrappedClassEnhanced() {
+        // Test all primitive types
+        
assertThat(ReflectionUtil.getWrappedClass(byte.class)).isEqualTo(Byte.class);
+        
assertThat(ReflectionUtil.getWrappedClass(boolean.class)).isEqualTo(Boolean.class);
+        
assertThat(ReflectionUtil.getWrappedClass(char.class)).isEqualTo(Character.class);
+        
assertThat(ReflectionUtil.getWrappedClass(short.class)).isEqualTo(Short.class);
+        
assertThat(ReflectionUtil.getWrappedClass(int.class)).isEqualTo(Integer.class);
+        
assertThat(ReflectionUtil.getWrappedClass(long.class)).isEqualTo(Long.class);
+        
assertThat(ReflectionUtil.getWrappedClass(float.class)).isEqualTo(Float.class);
+        
assertThat(ReflectionUtil.getWrappedClass(double.class)).isEqualTo(Double.class);
+        
assertThat(ReflectionUtil.getWrappedClass(void.class)).isEqualTo(Void.class);
+
+        // Test non-primitive type
+        
assertThat(ReflectionUtil.getWrappedClass(String.class)).isEqualTo(String.class);
+    }
+
+    @Test
+    public void testGetInterfacesEnhanced() {
+        // Test interface class
+        Set<Class<?>> interfaces = 
ReflectionUtil.getInterfaces(TestInterfaceEnhanced.class);
+        assertThat(interfaces).containsExactly(TestInterfaceEnhanced.class);
+
+        // Test implementation class
+        Set<Class<?>> implInterfaces = 
ReflectionUtil.getInterfaces(TestImpl.class);
+        assertThat(implInterfaces).contains(TestInterfaceEnhanced.class);
+
+        // Test class with multiple interfaces
+        Set<Class<?>> multiInterfaces = 
ReflectionUtil.getInterfaces(MultiInterfaceImpl.class);
+        assertThat(multiInterfaces).contains(TestInterfaceEnhanced.class, 
SecondInterface.class);
+    }
+
+    @Test
+    public void testGetAllFieldsEnhanced() {
+        // Test normal class
+        Field[] fields = ReflectionUtil.getAllFields(TestClassEnhanced.class);
+        assertThat(fields).hasSize(2); // f1, f2
+
+        // Test class with no fields
+        Field[] emptyFields = ReflectionUtil.getAllFields(EmptyClass.class);
+        assertThat(emptyFields).isEmpty();
+
+        // Test Object class
+        Field[] objectFields = ReflectionUtil.getAllFields(Object.class);
+        assertThat(objectFields).isEmpty();
+
+        // Test interface
+        Field[] interfaceFields = 
ReflectionUtil.getAllFields(TestInterfaceEnhanced.class);
+        assertThat(interfaceFields).isEmpty();
+    }
+
+    @Test
+    public void testGetField() throws NoSuchFieldException {
+        // Test normal field
+        Field field = ReflectionUtil.getField(TestClassEnhanced.class, "f1");
+        assertThat(field.getName()).isEqualTo("f1");
+
+        // Test inherited field
+        Field inheritedField = 
ReflectionUtil.getField(TestClassEnhanced.class, "f2");
+        assertThat(inheritedField.getName()).isEqualTo("f2");
+
+        // Test non-existent field
+        assertThatThrownBy(() -> 
ReflectionUtil.getField(TestClassEnhanced.class, "nonExistent"))
+                .isInstanceOf(NoSuchFieldException.class);
+    }
+
+    @Test
+    public void testGetFieldValueEnhanced() throws NoSuchFieldException {
+        TestClassEnhanced testObj = new TestClassEnhanced();
+        testObj.setValue("testValue");
+
+        // Test normal field value
+        String value = ReflectionUtil.getFieldValue(testObj, "f1");
+        assertThat(value).isEqualTo("testValue");
+
+        // Test inherited field value using getter since it's private
+        testObj.setF2(123);
+        Integer inheritedValue = testObj.getF2();
+        assertThat(inheritedValue).isEqualTo(123);
+
+        // Test null target
+        assertThatThrownBy(() -> ReflectionUtil.getFieldValue(null, 
"f1")).isInstanceOf(IllegalArgumentException.class);
+
+        // Test non-existent field
+        assertThatThrownBy(() -> ReflectionUtil.getFieldValue(testObj, 
"nonExistent"))
+                .isInstanceOf(NoSuchFieldException.class);
+    }
+
+    @Test
+    public void testSetFieldValueEnhanced() throws NoSuchFieldException {
+        TestClassEnhanced testObj = new TestClassEnhanced();
+
+        // Test setting field value
+        ReflectionUtil.setFieldValue(testObj, "f1", "newValue");
+        assertThat(testObj.getValue()).isEqualTo("newValue");
+
+        // Test setting inherited field value using setter since it's private
+        ReflectionUtil.setFieldValue(testObj, "f2", 456);
+        assertThat(testObj.getF2()).isEqualTo(456);
+
+        // Test null target
+        assertThatThrownBy(() -> ReflectionUtil.setFieldValue(null, "f1", 
"value"))
+                .isInstanceOf(IllegalArgumentException.class);
+
+        // Test non-existent field
+        assertThatThrownBy(() -> ReflectionUtil.setFieldValue(testObj, 
"nonExistent", "value"))
+                .isInstanceOf(NoSuchFieldException.class);
+    }
+
+    @Test
+    @EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11})

Review 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!
   ```



##########
common/src/test/java/org/apache/seata/common/util/NetAddressValidatorUtilTest.java:
##########
@@ -69,4 +69,141 @@ public void isLinkLocalIPv6WithZoneIndex() {
         
assertThat(NetAddressValidatorUtil.isLinkLocalIPv6WithZoneIndex("2409:8a5c:6730:4490:f0e8:b9ad:3b3d:e739%"))
                 .isFalse();
     }
+
+    // 以下是增强的测试用例

Review Comment:
   Same as above



##########
common/src/test/java/org/apache/seata/common/util/CollectionUtilsTest.java:
##########
@@ -255,4 +258,337 @@ public void test_getLast() {
         list.add("Bar");
         Assertions.assertEquals("Bar", CollectionUtils.getLast(list));
     }
+
+    // 以下是增强的测试用例

Review Comment:
   Useless Chinese annotations



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to