You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/26 11:48:35 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #21752: fix issue: add unit test for ReflectiveUtil.

sandynz commented on code in PR #21752:
URL: https://github.com/apache/shardingsphere/pull/21752#discussion_r1005568326


##########
infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java:
##########
@@ -0,0 +1,43 @@
+package org.apache.shardingsphere.infra.util.reflect;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ReflectiveUtilTest {

Review Comment:
   `final` should be added for class



##########
infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java:
##########
@@ -0,0 +1,43 @@
+package org.apache.shardingsphere.infra.util.reflect;

Review Comment:
   License header should be added



##########
infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java:
##########
@@ -0,0 +1,43 @@
+package org.apache.shardingsphere.infra.util.reflect;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ReflectiveUtilTest {
+
+    @Test
+    public void testGetFieldValue() {
+        UserPojo pojo = new UserPojo("test");
+        String fieldValue = (String)ReflectiveUtil.getFieldValue(pojo, "foo");

Review Comment:
   Blank is necessary after `(String)` for check style



##########
infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java:
##########
@@ -0,0 +1,43 @@
+package org.apache.shardingsphere.infra.util.reflect;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ReflectiveUtilTest {
+
+    @Test
+    public void testGetFieldValue() {

Review Comment:
   Unit test method name should start with `assert`, e.g. assertGetFieldValue



##########
infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java:
##########
@@ -0,0 +1,43 @@
+package org.apache.shardingsphere.infra.util.reflect;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ReflectiveUtilTest {
+
+    @Test
+    public void testGetFieldValue() {
+        UserPojo pojo = new UserPojo("test");
+        String fieldValue = (String)ReflectiveUtil.getFieldValue(pojo, "foo");
+        assertTrue("test".equals(fieldValue));
+    }
+
+    @Test
+    public void testSetField() {
+        UserPojo pojo = new UserPojo();
+        ReflectiveUtil.setField(pojo, "foo", "test");
+        assertTrue("test".equals(pojo.getFoo()));
+    }
+
+    @Test
+    public void testSetStaticField() {
+        ReflectiveUtil.setStaticField(UserPojo.class, "bar", "test");
+        assertTrue("test".equals(UserPojo.bar));
+    }
+
+    @AllArgsConstructor
+    @NoArgsConstructor

Review Comment:
   1, If XxxArgsConstructor is not required, then they could be removed.
   
   2, It's better to mark it as `private final` for inner class.
   



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org