Do some Optimizations on the UT Class
authorGuangrongFu <fu.guangrong@zte.com.cn>
Thu, 23 Feb 2017 10:24:50 +0000 (18:24 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Thu, 23 Feb 2017 10:24:50 +0000 (18:24 +0800)
Get the getter name using PropertyDescriptor

Change-Id: Ib51ac622c316f20fb8fd365b66529eda265f65d1
Issue-ID: HOLMES-47
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java

index b3e6b38..5096db3 100644 (file)
@@ -15,6 +15,7 @@
  */\r
 package org.openo.holmes.rulemgt.db;\r
 \r
+import java.beans.PropertyDescriptor;\r
 import java.lang.reflect.Field;\r
 import java.lang.reflect.Method;\r
 import java.util.ArrayList;\r
@@ -92,16 +93,16 @@ public class CorrelationRuleQueryDao {
             String whereSql = " WHERE ";\r
 \r
             for (Field field : fields) {\r
-                String methodName = getMethodName(field);\r
-\r
-                // If these lines are removed, Jacoco will cause an exception when calculation the coverage of UT\r
-                // Remove it if someday Jacoco solve this problem\r
-                if (methodName.contains("jacoco")){\r
+                // Jacoco will cause an exception when calculating the coverage of the UT\r
+                // Remove this if jacoco solves this problem in the future\r
+                if (field.getName().contains("jacoco")){\r
                     continue;\r
                 }\r
 \r
-                Method method = clazz.getMethod(methodName);\r
-                Object o = method.invoke(ruleQueryCondition);\r
+                PropertyDescriptor pd = new PropertyDescriptor(field.getName(),\r
+                        clazz);\r
+                Method getMethod = pd.getReadMethod();\r
+                Object o = getMethod.invoke(ruleQueryCondition);\r
                 if (o != null) {\r
                     String tempName = field.getName();\r
                     if ("enabled".equals(tempName) && (int) o != RuleMgtConstant.STATUS_RULE_ALL) {\r