You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/10/29 02:14:05 UTC

[shardingsphere] branch master updated: Unit test cases for the ReflectiveUtil (#21778)

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

zhonghongsheng 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 efa671a4e29 Unit test cases for the ReflectiveUtil (#21778)
efa671a4e29 is described below

commit efa671a4e2958e62f0967aa270015f6d46f11042
Author: Ishu Thakur <45...@users.noreply.github.com>
AuthorDate: Sat Oct 29 07:43:56 2022 +0530

    Unit test cases for the ReflectiveUtil (#21778)
    
    * adding unit tests as ReflectiveUtilTest for ReflectiveUtil
    
    * fixing the check style validations
    
    * making inner class private in ReflectiveUtilTest
---
 .../infra/util/reflect/ReflectiveUtilTest.java     | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java
new file mode 100644
index 00000000000..32fc8dd207a
--- /dev/null
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtilTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.infra.util.reflect;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+import lombok.AccessLevel;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class ReflectiveUtilTest {
+    
+    @Test
+    public void assertGetFieldValue() throws IllegalAccessError {
+        ReflectiveFixture reflectiveFixture = new ReflectiveFixture("bar");
+        assertThat(ReflectiveUtil.getFieldValue(reflectiveFixture, "value"), is("bar"));
+    }
+    
+    @Test
+    public void assertSetField() throws IllegalAccessError {
+        ReflectiveFixture reflectiveFixture = new ReflectiveFixture();
+        ReflectiveUtil.setField(reflectiveFixture, "value", "foo");
+        assertThat(ReflectiveUtil.getFieldValue(reflectiveFixture, "value"), is("foo"));
+    }
+    
+    @Test
+    public void assertSetStaticField() throws IllegalAccessError {
+        ReflectiveFixture reflectiveFixture = new ReflectiveFixture();
+        ReflectiveUtil.setStaticField(reflectiveFixture.getClass(), "staticValue", "foo");
+        assertThat(ReflectiveUtil.getFieldValue(reflectiveFixture, "staticValue"), is("foo"));
+    }
+    
+    @AllArgsConstructor
+    @NoArgsConstructor
+    @Getter
+    @Setter(AccessLevel.PRIVATE)
+    private static final class ReflectiveFixture {
+        
+        private static String staticValue;
+        
+        private String value;
+    }
+}