From 7b5f7f8627d6e3cc267b4f7eefeb73d2efb31f96 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 11 Jul 2019 10:10:17 -0400 Subject: Fix checkstyle issues in common/gson Also deleted the checkstyle suppression file. Change-Id: I6d310af32d6d4be9633a8f88745447f40a566af7 Issue-ID: POLICY-1074 Signed-off-by: Jim Hahn --- .../onap/policy/common/gson/internal/Adapter.java | 33 +++++++++++++++++----- .../policy/common/gson/internal/ClassWalker.java | 8 +++++- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'gson/src/main/java/org/onap') diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java index c7b3bc98..174b4912 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java @@ -41,6 +41,11 @@ public class Adapter { */ private static final Pattern VALID_NAME_PAT = Pattern.compile("[a-zA-Z_]\\w*"); + /** + * Factory to access objects. Overridden by junit tests. + */ + private static Factory factory = new Factory(); + /** * Name of the property within the json structure containing the item. */ @@ -157,7 +162,7 @@ public class Adapter { * @return {@code true} if the field is managed by the walker, {@code false} otherwise */ public static boolean isManaged(Field field) { - return VALID_NAME_PAT.matcher(field.getName()).matches(); + return VALID_NAME_PAT.matcher(factory.getName(field)).matches(); } /** @@ -168,7 +173,7 @@ public class Adapter { * otherwise */ public static boolean isManaged(Method method) { - return VALID_NAME_PAT.matcher(method.getName()).matches(); + return VALID_NAME_PAT.matcher(factory.getName(method)).matches(); } /** @@ -185,7 +190,7 @@ public class Adapter { } // no name provided - use it as is - return (isManaged(field) ? field.getName() : null); + return (isManaged(field) ? factory.getName(field) : null); } /** @@ -204,7 +209,7 @@ public class Adapter { return null; } - String name = method.getName(); + String name = factory.getName(method); if (name.startsWith("get")) { return name.substring(3); @@ -238,7 +243,7 @@ public class Adapter { return null; } - String name = method.getName(); + String name = factory.getName(method); if (name.startsWith("set")) { return name.substring(3); @@ -284,7 +289,7 @@ public class Adapter { * @return the field fully qualified name */ public static String getQualifiedName(Field field) { - return (field.getDeclaringClass().getName() + "." + field.getName()); + return (field.getDeclaringClass().getName() + "." + factory.getName(field)); } /** @@ -294,7 +299,7 @@ public class Adapter { * @return the method's fully qualified name */ public static String getQualifiedName(Method method) { - return (method.getDeclaringClass().getName() + "." + method.getName()); + return (method.getDeclaringClass().getName() + "." + factory.getName(method)); } /** @@ -340,4 +345,18 @@ public class Adapter { return conv; } } + + /** + * Factory used to access various objects. + */ + public static class Factory { + + public String getName(Field field) { + return field.getName(); + } + + public String getName(Method method) { + return method.getName(); + } + } } diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java index 89e4f89d..ef4eaae3 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java @@ -241,7 +241,7 @@ public class ClassWalker { return; } - String name = Adapter.detmPropName(field); + String name = detmPropName(field); if (name == null) { // invalid name return; @@ -386,4 +386,10 @@ public class ClassWalker { private String getFqdn(Method method) { return (method.getDeclaringClass().getName() + "." + method.getName()); } + + // these may be overridden by junit tests + + protected String detmPropName(Field field) { + return Adapter.detmPropName(field); + } } -- cgit 1.2.3-korg