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/07/15 10:42:12 UTC

[GitHub] [shardingsphere] sunkai-cai opened a new pull request, #19246: Create ReflectionUtilTest.java

sunkai-cai opened a new pull request, #19246:
URL: https://github.com/apache/shardingsphere/pull/19246

   Fixes #15703.
   
   


-- 
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


[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #19246: Create ReflectionUtilTest.java

Posted by GitBox <gi...@apache.org>.
terrymanu commented on code in PR #19246:
URL: https://github.com/apache/shardingsphere/pull/19246#discussion_r922126691


##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public final class ReflectionUtilTest {
+
+    @Test
+    public void assertSetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.setFieldValue(reflectionSimple, "name", "sharding-sphere");
+        assertThat(reflectionSimple.getName(), is("sharding-sphere"));
+    }
+
+    @Test
+    public void assertGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        Integer age = ReflectionUtil.getFieldValue(reflectionSimple, "age", Integer.class);
+        assertThat(age, is(18));
+    }
+
+    @Test
+    public void assertGetStaticFieldValue() throws Exception {
+        ReflectionSimple.setType("ReflectionSimple");
+        String fieldValue = ReflectionUtil.getStaticFieldValue(ReflectionSimple.class, "type", String.class);
+        assertThat(fieldValue, is("ReflectionSimple"));
+    }
+
+    @Test
+    public void assertInvokeMethodAndGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.invokeMethod(reflectionSimple, "setName", new Class[]{String.class}, new Object[]{"apache"});
+        assertThat(reflectionSimple.getName(), is("apache"));
+    }
+
+    private static class ReflectionSimple {
+
+        private static String type;
+
+        private String name;
+
+        private final Integer age;

Review Comment:
   Is it necessary to use Integer, how about use int



##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public final class ReflectionUtilTest {
+
+    @Test
+    public void assertSetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.setFieldValue(reflectionSimple, "name", "sharding-sphere");
+        assertThat(reflectionSimple.getName(), is("sharding-sphere"));
+    }
+
+    @Test
+    public void assertGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        Integer age = ReflectionUtil.getFieldValue(reflectionSimple, "age", Integer.class);
+        assertThat(age, is(18));
+    }
+
+    @Test
+    public void assertGetStaticFieldValue() throws Exception {
+        ReflectionSimple.setType("ReflectionSimple");
+        String fieldValue = ReflectionUtil.getStaticFieldValue(ReflectionSimple.class, "type", String.class);
+        assertThat(fieldValue, is("ReflectionSimple"));
+    }
+
+    @Test
+    public void assertInvokeMethodAndGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.invokeMethod(reflectionSimple, "setName", new Class[]{String.class}, new Object[]{"apache"});
+        assertThat(reflectionSimple.getName(), is("apache"));
+    }
+
+    private static class ReflectionSimple {
+
+        private static String type;
+
+        private String name;
+
+        private final Integer age;
+
+        ReflectionSimple() {
+            age = 18;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        private void setName(final String name) {
+            this.name = name;
+        }
+
+        public static void setType(final String type) {
+            ReflectionSimple.type = type;
+        }
+
+        private Integer getAge() {
+            return age;

Review Comment:
   Please use lombok annotation to instead of getter and setter



##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public final class ReflectionUtilTest {
+
+    @Test
+    public void assertSetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.setFieldValue(reflectionSimple, "name", "sharding-sphere");
+        assertThat(reflectionSimple.getName(), is("sharding-sphere"));
+    }
+
+    @Test
+    public void assertGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        Integer age = ReflectionUtil.getFieldValue(reflectionSimple, "age", Integer.class);
+        assertThat(age, is(18));
+    }
+
+    @Test
+    public void assertGetStaticFieldValue() throws Exception {
+        ReflectionSimple.setType("ReflectionSimple");
+        String fieldValue = ReflectionUtil.getStaticFieldValue(ReflectionSimple.class, "type", String.class);
+        assertThat(fieldValue, is("ReflectionSimple"));
+    }
+
+    @Test
+    public void assertInvokeMethodAndGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.invokeMethod(reflectionSimple, "setName", new Class[]{String.class}, new Object[]{"apache"});
+        assertThat(reflectionSimple.getName(), is("apache"));
+    }
+
+    private static class ReflectionSimple {
+
+        private static String type;
+
+        private String name;
+
+        private final Integer age;
+
+        ReflectionSimple() {
+            age = 18;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        private void setName(final String name) {
+            this.name = name;
+        }
+
+        public static void setType(final String type) {
+            ReflectionSimple.type = type;
+        }
+
+        private Integer getAge() {
+            return age;
+        }
+    }
+

Review Comment:
   Please remove useless blank line



-- 
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


[GitHub] [shardingsphere] codecov-commenter commented on pull request #19246: Create ReflectionUtilTest.java

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #19246:
URL: https://github.com/apache/shardingsphere/pull/19246#issuecomment-1185470936

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/19246?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#19246](https://codecov.io/gh/apache/shardingsphere/pull/19246?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (1a53a46) into [master](https://codecov.io/gh/apache/shardingsphere/commit/457ca745d8a7f1bbdc56e65237e625a558811d57?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (457ca74) will **decrease** coverage by `0.24%`.
   > The diff coverage is `86.66%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #19246      +/-   ##
   ============================================
   - Coverage     59.50%   59.26%   -0.25%     
   - Complexity     2326     2330       +4     
   ============================================
     Files          3807     3809       +2     
     Lines         54700    54339     -361     
     Branches       9240     9246       +6     
   ============================================
   - Hits          32551    32203     -348     
   + Misses        19412    19396      -16     
   - Partials       2737     2740       +3     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/19246?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../common/statement/ddl/AlterDiskgroupStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvY29tbW9uL3N0YXRlbWVudC9kZGwvQWx0ZXJEaXNrZ3JvdXBTdGF0ZW1lbnQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ment/oracle/ddl/OracleAlterDiskgroupStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9zdGF0ZW1lbnQvb3JhY2xlL2RkbC9PcmFjbGVBbHRlckRpc2tncm91cFN0YXRlbWVudC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ler/checker/ShardingTableRuleStatementChecker.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctZGlzdHNxbC9zaGFyZGluZ3NwaGVyZS1zaGFyZGluZy1kaXN0c3FsLWhhbmRsZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NoYXJkaW5nL2Rpc3RzcWwvaGFuZGxlci9jaGVja2VyL1NoYXJkaW5nVGFibGVSdWxlU3RhdGVtZW50Q2hlY2tlci5qYXZh) | `39.05% <100.00%> (ø)` | |
   | [...orkerid/generator/StandaloneWorkerIdGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtc3RhbmRhbG9uZS1tb2RlL3NoYXJkaW5nc3BoZXJlLXN0YW5kYWxvbmUtbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvc3RhbmRhbG9uZS93b3JrZXJpZC9nZW5lcmF0b3IvU3RhbmRhbG9uZVdvcmtlcklkR2VuZXJhdG9yLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | [...r/statement/impl/OracleDDLStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1vcmFjbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NxbC9wYXJzZXIvb3JhY2xlL3Zpc2l0b3Ivc3RhdGVtZW50L2ltcGwvT3JhY2xlRERMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `88.09% <100.00%> (+0.04%)` | :arrow_up: |
   | [...l/parser/core/database/visitor/SQLVisitorRule.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWVuZ2luZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9jb3JlL2RhdGFiYXNlL3Zpc2l0b3IvU1FMVmlzaXRvclJ1bGUuamF2YQ==) | `100.00% <100.00%> (ø)` | |
   | [...eterized/jaxb/cases/domain/SQLParserTestCases.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtdGVzdC9zaGFyZGluZ3NwaGVyZS1wYXJzZXItdGVzdC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvdGVzdC9zcWwvcGFyc2VyL3BhcmFtZXRlcml6ZWQvamF4Yi9jYXNlcy9kb21haW4vU1FMUGFyc2VyVGVzdENhc2VzLmphdmE=) | `99.27% <100.00%> (-0.60%)` | :arrow_down: |
   | [...statement/ddl/AlterDiskgroupStatementTestCase.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtdGVzdC9zaGFyZGluZ3NwaGVyZS1wYXJzZXItdGVzdC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvdGVzdC9zcWwvcGFyc2VyL3BhcmFtZXRlcml6ZWQvamF4Yi9jYXNlcy9kb21haW4vc3RhdGVtZW50L2RkbC9BbHRlckRpc2tncm91cFN0YXRlbWVudFRlc3RDYXNlLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | [...nd/text/distsql/ral/hint/enums/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2hpbnQvZW51bXMvSGludFNvdXJjZVR5cGUuamF2YQ==) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   | ... and [109 more](https://codecov.io/gh/apache/shardingsphere/pull/19246/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/19246?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/19246?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [f0757e7...1a53a46](https://codecov.io/gh/apache/shardingsphere/pull/19246?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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


[GitHub] [shardingsphere] terrymanu merged pull request #19246: Create ReflectionUtilTest.java

Posted by GitBox <gi...@apache.org>.
terrymanu merged PR #19246:
URL: https://github.com/apache/shardingsphere/pull/19246


-- 
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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #19246: Create ReflectionUtilTest.java

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on code in PR #19246:
URL: https://github.com/apache/shardingsphere/pull/19246#discussion_r922152994


##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public final class ReflectionUtilTest {
+
+    @Test
+    public void assertSetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.setFieldValue(reflectionSimple, "name", "sharding-sphere");
+        assertThat(reflectionSimple.getName(), is("sharding-sphere"));
+    }
+
+    @Test
+    public void assertGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        Integer age = ReflectionUtil.getFieldValue(reflectionSimple, "age", Integer.class);
+        assertThat(age, is(18));
+    }
+
+    @Test
+    public void assertGetStaticFieldValue() throws Exception {
+        ReflectionSimple.setType("ReflectionSimple");
+        String fieldValue = ReflectionUtil.getStaticFieldValue(ReflectionSimple.class, "type", String.class);
+        assertThat(fieldValue, is("ReflectionSimple"));
+    }
+
+    @Test
+    public void assertInvokeMethodAndGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.invokeMethod(reflectionSimple, "setName", new Class[]{String.class}, new Object[]{"apache"});
+        assertThat(reflectionSimple.getName(), is("apache"));
+    }
+
+    private static class ReflectionSimple {
+
+        private static String type;
+
+        private String name;
+
+        private final Integer age;
+
+        ReflectionSimple() {
+            age = 18;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        private void setName(final String name) {
+            this.name = name;
+        }
+
+        public static void setType(final String type) {
+            ReflectionSimple.type = type;
+        }
+
+        private Integer getAge() {
+            return age;
+        }
+    }
+

Review Comment:
   Thanks for the tip.



-- 
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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #19246: Create ReflectionUtilTest.java

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on code in PR #19246:
URL: https://github.com/apache/shardingsphere/pull/19246#discussion_r922153712


##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public final class ReflectionUtilTest {
+
+    @Test
+    public void assertSetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.setFieldValue(reflectionSimple, "name", "sharding-sphere");
+        assertThat(reflectionSimple.getName(), is("sharding-sphere"));
+    }
+
+    @Test
+    public void assertGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        Integer age = ReflectionUtil.getFieldValue(reflectionSimple, "age", Integer.class);
+        assertThat(age, is(18));
+    }
+
+    @Test
+    public void assertGetStaticFieldValue() throws Exception {
+        ReflectionSimple.setType("ReflectionSimple");
+        String fieldValue = ReflectionUtil.getStaticFieldValue(ReflectionSimple.class, "type", String.class);
+        assertThat(fieldValue, is("ReflectionSimple"));
+    }
+
+    @Test
+    public void assertInvokeMethodAndGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.invokeMethod(reflectionSimple, "setName", new Class[]{String.class}, new Object[]{"apache"});
+        assertThat(reflectionSimple.getName(), is("apache"));
+    }
+
+    private static class ReflectionSimple {
+
+        private static String type;
+
+        private String name;
+
+        private final Integer age;
+
+        ReflectionSimple() {
+            age = 18;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        private void setName(final String name) {
+            this.name = name;
+        }
+
+        public static void setType(final String type) {
+            ReflectionSimple.type = type;
+        }
+
+        private Integer getAge() {
+            return age;

Review Comment:
   ok



-- 
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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #19246: Create ReflectionUtilTest.java

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on code in PR #19246:
URL: https://github.com/apache/shardingsphere/pull/19246#discussion_r922154135


##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public final class ReflectionUtilTest {
+
+    @Test
+    public void assertSetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.setFieldValue(reflectionSimple, "name", "sharding-sphere");
+        assertThat(reflectionSimple.getName(), is("sharding-sphere"));
+    }
+
+    @Test
+    public void assertGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        Integer age = ReflectionUtil.getFieldValue(reflectionSimple, "age", Integer.class);
+        assertThat(age, is(18));
+    }
+
+    @Test
+    public void assertGetStaticFieldValue() throws Exception {
+        ReflectionSimple.setType("ReflectionSimple");
+        String fieldValue = ReflectionUtil.getStaticFieldValue(ReflectionSimple.class, "type", String.class);
+        assertThat(fieldValue, is("ReflectionSimple"));
+    }
+
+    @Test
+    public void assertInvokeMethodAndGetFieldValue() throws Exception {
+        ReflectionSimple reflectionSimple = new ReflectionSimple();
+        ReflectionUtil.invokeMethod(reflectionSimple, "setName", new Class[]{String.class}, new Object[]{"apache"});
+        assertThat(reflectionSimple.getName(), is("apache"));
+    }
+
+    private static class ReflectionSimple {
+
+        private static String type;
+
+        private String name;
+
+        private final Integer age;

Review Comment:
   look like good



-- 
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