This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 34e5fdfd0c7 Create ReflectionUtilTest.java (#19246)
34e5fdfd0c7 is described below

commit 34e5fdfd0c720b93f181c084c7ed198a08b45b02
Author: skai <[email protected]>
AuthorDate: Fri Jul 15 23:41:34 2022 +0800

    Create ReflectionUtilTest.java (#19246)
    
    * Create ReflectionUtilTest.java
    
    * change from review
    
    Co-authored-by: skai <[email protected]>
---
 .../pipeline/core/util/ReflectionUtilTest.java     | 70 ++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java
new file mode 100644
index 00000000000..d5461e44b02
--- /dev/null
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/ReflectionUtilTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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 lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
+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 {
+
+        @Setter
+        private static String type;
+
+        @Getter
+        @Setter(AccessLevel.PRIVATE)
+        private String name;
+
+        @Getter(AccessLevel.PRIVATE)
+        private final int age = 18;
+    }
+}

Reply via email to