This is an automated email from the ASF dual-hosted git repository.
cancai pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new 8316e64a0 [ISSUES-3063][Improve] Improve ReflectUtils test code
coverage (#3556)
8316e64a0 is described below
commit 8316e64a0d13a38aaeda5f7b649490bb15aa8526
Author: zhengke zhou <[email protected]>
AuthorDate: Sun Feb 18 10:04:33 2024 +0800
[ISSUES-3063][Improve] Improve ReflectUtils test code coverage (#3556)
---
.../streampark/common/util/ReflectUtilsTest.scala | 48 ++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git
a/streampark-common/src/test/scala/org/apache/streampark/common/util/ReflectUtilsTest.scala
b/streampark-common/src/test/scala/org/apache/streampark/common/util/ReflectUtilsTest.scala
new file mode 100644
index 000000000..6f30bf9fa
--- /dev/null
+++
b/streampark-common/src/test/scala/org/apache/streampark/common/util/ReflectUtilsTest.scala
@@ -0,0 +1,48 @@
+/*
+ * 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.streampark.common.util
+
+import org.scalatest.funsuite.AnyFunSuite
+
+class ReflectUtilsTest extends AnyFunSuite {
+ case class TestObject(value: String)
+
+ test("getField should return the correct field") {
+ val field = ReflectUtils.getField(classOf[TestObject], "value")
+ assert(field.getName == "value")
+ assert(field.getType == classOf[String])
+ }
+
+ test("getField should handle non-existent fields gracefully") {
+ val field = ReflectUtils.getField(classOf[TestObject], "nonExistentField")
+ assert(field == null)
+ }
+
+ test("getFieldValue should handle non-existent field gracefully") {
+ val obj = new TestObject("test")
+ val value = ReflectUtils.getFieldValue(obj, "nonExistentField")
+ assert(value == null)
+ }
+
+ test("setFieldValue should throw IllegalArgumentException for non-existent
field") {
+ val obj = new TestObject("test")
+ assertThrows[IllegalArgumentException] {
+ ReflectUtils.setFieldValue(obj, "nonExistentField", "value")
+ }
+ }
+}