From 39305c31cee623b44e56ca7b944aada2747d8f31 Mon Sep 17 00:00:00 2001 From: "vamshi.nemalikonda" Date: Tue, 10 Jul 2018 19:44:02 +0530 Subject: fixed Checkstyle warnings Issue-ID: POLICY-881 Signed-off-by: vamshi.nemalikonda Change-Id: I4057306bec83a48921c90a081fb9752f663ee3b6 --- .../policy/common/utils/test/ExceptionsTester.java | 109 +++++----- .../policy/common/utils/test/ThrowablesTester.java | 230 +++++++++++++-------- 2 files changed, 201 insertions(+), 138 deletions(-) (limited to 'utils-test') diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java index 3a43b943..7208748a 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java @@ -1,21 +1,21 @@ /* - * ============LICENSE_START======================================================= + * ============LICENSE_START==================================================== * Common Utils-Test - * ================================================================================ + * ============================================================================= * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============================================================================= * Licensed 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. - * ============LICENSE_END========================================================= + * ============LICENSE_END====================================================== */ package org.onap.policy.common.utils.test; @@ -34,18 +34,19 @@ public class ExceptionsTester extends ThrowablesTester { /** * Runs tests, on an Exception subclass, for all of the standard - * constructors. If the Exception subclass does not support a given type of - * constructor, then it skips that test. - * - * @param claz - * subclass to be tested + * constructors. If the Exception subclass does not support a given + * type of constructor, then it skips that test. + * + * @param claz subclass to be tested + * @param Type of the class + * * @return the number of constructors that were found/tested * @throws ConstructionError * if the Exception subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public int test(Class claz) { + public int test(final Class claz) { int ncons = testAllException(claz); assertTrue(ncons > 0); @@ -55,19 +56,20 @@ public class ExceptionsTester extends ThrowablesTester { /** * Runs tests, on an Exception subclass, for all of the standard - * constructors. If the Exception subclass does not support a given type of - * constructor, then it skips that test. Does not throw an exception - * if no standard constructors are found. - * - * @param claz - * subclass to be tested + * constructors. If the Exception subclass does not support a given + * type of constructor, then it skips that test. Does not throw + * an exception if no standard constructors are found. + * + * @param claz subclass to be tested + * @param type of the class + * * @return the number of constructors that were found/tested * @throws ConstructionError * if the Exception subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public int testAllException(Class claz) { + public int testAllException(final Class claz) { int ncons = 0; ncons += testAllThrowable(claz); @@ -87,12 +89,13 @@ public class ExceptionsTester extends ThrowablesTester { *
  • getCause() returns the original cause passed to the * constructor
  • * - * - * If the Exception subclass does not support this type of constructor, then - * this method simply returns. - * - * @param claz - * subclass to be tested + * + * If the Exception subclass does not support this type of constructor, + * then this method simply returns. + * + * @param claz subclass to be tested + * @param Type of the class + * * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError @@ -100,8 +103,10 @@ public class ExceptionsTester extends ThrowablesTester { * @throws AssertionError * if the constructed objects fail to pass various tests */ - public int testException(Class claz) { - Constructor cons = getConstructor(claz, "exception", Exception.class); + public int testException(final Class claz) { + Constructor cons = getConstructor(claz, "exception", + Exception.class); + if (cons == null) { return 0; } @@ -117,28 +122,31 @@ public class ExceptionsTester extends ThrowablesTester { } /** - * Tests exceptions created via the constructor that takes a String and an - * Exception. Verifies that: + * Tests exceptions created via the constructor that takes a String + * and an Exception. Verifies that: *
      *
    • toString() returns a non-null value
    • - *
    • getMessage() returns the original message passed to the - * constructor
    • + *
    • getMessage() returns the original message passed to + * the constructor
    • *
    • getCause() returns the original cause passed to the * constructor
    • *
    - * - * If the Exception subclass does not support this type of constructor, then - * this method simply returns. - * - * @param claz - * subclass to be tested + * + * If the Exception subclass does not support this type of + * constructor, then this method simply returns. + * + * @param claz subclass to be tested + * @param Type of the class + * * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError * if the Exception subclass cannot be constructed */ - public int testStringException(Class claz) { - Constructor cons = getConstructor(claz, "string-exception", String.class, Exception.class); + public int testStringException( + final Class claz) { + Constructor cons = getConstructor(claz, "string-exception", + String.class, Exception.class); if (cons == null) { return 0; } @@ -165,20 +173,25 @@ public class ExceptionsTester extends ThrowablesTester { *
  • suppressed exceptions can be added, if enabled
  • *
  • the stack trace can be added, if enabled
  • * - * - * If the Exception subclass does not support this type of constructor, then - * this method simply returns. - * - * @param claz - * subclass to be tested + * + * If the Exception subclass does not support this type of constructor, + * then this method simply returns. + * + * @param claz subclass to be tested + * @param Type of the class + * * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError * if the Exception subclass cannot be constructed */ - public int testStringExceptionBooleanBoolean(Class claz) { - Constructor cons = getConstructor(claz, "string-exception-flags", String.class, Exception.class, - Boolean.TYPE, Boolean.TYPE); + public int testStringExceptionBooleanBoolean( + final Class claz) { + + Constructor cons = getConstructor(claz, + "string-exception-flags", String.class, Exception.class, + Boolean.TYPE, Boolean.TYPE); + if (cons == null) { return 0; } diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java index 4a8da3b4..c77b7813 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java @@ -1,21 +1,21 @@ /* - * ============LICENSE_START======================================================= + * ============LICENSE_START==================================================== * Common Utils-Test - * ================================================================================ + * ============================================================================= * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============================================================================= * Licensed 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. - * ============LICENSE_END========================================================= + * ============LICENSE_END====================================================== */ package org.onap.policy.common.utils.test; @@ -37,36 +37,43 @@ import org.slf4j.LoggerFactory; */ public class ThrowablesTester { - private static Logger logger = LoggerFactory.getLogger(ThrowablesTester.class); + private static Logger logger = + LoggerFactory.getLogger(ThrowablesTester.class); - public static final String EXPECTED_EXCEPTION_MSG = "expected exception"; - private static final String EXPECTED_SUPPRESSED_EXCEPTION_MSG = "expected suppressed exception"; + public static final String EXPECTED_EXCEPTION_MSG = + "expected exception"; + private static final String EXPECTED_SUPPRESSED_EXCEPTION_MSG = + "expected suppressed exception"; /** * Passed as a "cause" to constructors. */ - public static final Exception CAUSE = new Exception(EXPECTED_EXCEPTION_MSG); + public static final Exception CAUSE = + new Exception(EXPECTED_EXCEPTION_MSG); /** * Passed to new objects via the addSuppressed() method.. */ - public static final Throwable SUPPRESSED = new Throwable(EXPECTED_SUPPRESSED_EXCEPTION_MSG); + public static final Throwable SUPPRESSED = + new Throwable(EXPECTED_SUPPRESSED_EXCEPTION_MSG); /** - * Runs tests, on an Throwable subclass, for all of the standard - * constructors. If the Throwable subclass does not support a given type of - * constructor, then it skips that test. Does not throw an exception - * if no standard constructors are found. - * - * @param claz - * subclass to be tested + * Runs tests, on an Throwable subclass, for all of the + * standard constructors. If the Throwable subclass does + * not support a given type of constructor, then it skips + * that test. Does not throw an exception if no + * standard constructors are found. + * + * @param claz subclass to be tested + * @param To be defined * @return the number of constructors that were found/tested * @throws ConstructionError * if the Throwable subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final int testAllThrowable(Class claz) { + public final int testAllThrowable( + final Class claz) { int ncons = 0; ncons += testDefault(claz); @@ -86,12 +93,12 @@ public class ThrowablesTester { *
  • getMessage() returns null
  • *
  • getCause() returns null
  • * - * - * If the Throwable subclass does not support this type of constructor, then - * this method simply returns. - * - * @param claz - * subclass to be tested + * + * If the Throwable subclass does not support this type of + * constructor, then this method simply returns. + * + * @param claz subclass to be tested + * @param to be defined * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError @@ -99,7 +106,8 @@ public class ThrowablesTester { * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final int testDefault(Class claz) { + public final int testDefault( + final Class claz) { Constructor cons = getConstructor(claz, "default"); if (cons == null) { return 0; @@ -123,12 +131,13 @@ public class ThrowablesTester { * constructor *
  • getCause() returns null
  • * - * - * If the Throwable subclass does not support this type of constructor, then - * this method simply returns. - * + * + * If the Throwable subclass does not support this type of constructor, + * then this method simply returns. + * * @param claz * subclass to be tested + * @param to be defined * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError @@ -136,8 +145,9 @@ public class ThrowablesTester { * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final int testString(Class claz) { - Constructor cons = getConstructor(claz, "string", String.class); + public final int testString(final Class claz) { + Constructor cons = getConstructor(claz, "string", + String.class); if (cons == null) { return 0; } @@ -160,12 +170,13 @@ public class ThrowablesTester { *
  • getCause() returns the original cause passed to the * constructor
  • * - * - * If the Throwable subclass does not support this type of constructor, then - * this method simply returns. - * + * + * If the Throwable subclass does not support this type of constructor, + * then this method simply returns. + * * @param claz * subclass to be tested + * @param to be defined * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError @@ -173,8 +184,10 @@ public class ThrowablesTester { * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final int testThrowable(Class claz) { - Constructor cons = getConstructor(claz, "throwable", Throwable.class); + public final int testThrowable( + final Class claz) { + Constructor cons = getConstructor(claz, "throwable", + Throwable.class); if (cons == null) { return 0; } @@ -189,8 +202,8 @@ public class ThrowablesTester { } /** - * Tests Throwable objects created via the constructor that takes a String - * and a Throwable. Verifies that: + * Tests Throwable objects created via the constructor that takes + * a String and a Throwable. Verifies that: *
      *
    • toString() returns a non-null value
    • *
    • getMessage() returns the original message passed to the @@ -198,12 +211,12 @@ public class ThrowablesTester { *
    • getCause() returns the original cause passed to the * constructor
    • *
    - * - * If the Throwable subclass does not support this type of constructor, then - * this method simply returns. - * - * @param claz - * subclass to be tested + * + * If the Throwable subclass does not support this type of constructor, + * then this method simply returns. + * + * @param claz subclass to be tested + * @param to be defined * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError @@ -211,8 +224,10 @@ public class ThrowablesTester { * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final int testStringThrowable(Class claz) { - Constructor cons = getConstructor(claz, "string-throwable", String.class, Throwable.class); + public final int testStringThrowable( + final Class claz) { + Constructor cons = getConstructor(claz, "string-throwable", + String.class, Throwable.class); if (cons == null) { return 0; } @@ -227,8 +242,8 @@ public class ThrowablesTester { } /** - * Tests Throwable objects created via the constructor that takes a String, - * a Throwable, and two booleans. Verifies that: + * Tests Throwable objects created via the constructor that takes + * a String, a Throwable, and two booleans. Verifies that: *
      *
    • toString() returns a non-null value
    • *
    • getMessage() returns the original message passed to the @@ -238,12 +253,13 @@ public class ThrowablesTester { *
    • suppressed exceptions can be added, if enabled
    • *
    • the stack trace can be added, if enabled
    • *
    - * - * If the Throwable subclass does not support this type of constructor, then - * this method simply returns. - * + * + * If the Throwable subclass does not support this type of constructor, + * then this method simply returns. + * * @param claz * subclass to be tested + * @param to be defined * @return {@code 1}, if the subclass supports this type of constructor, * {@code 0} otherwise * @throws ConstructionError @@ -251,9 +267,13 @@ public class ThrowablesTester { * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final int testStringThrowableBooleanBoolean(Class claz) { - Constructor cons = getConstructor(claz, "string-throwable-flags", String.class, Throwable.class, - Boolean.TYPE, Boolean.TYPE); + public final int + testStringThrowableBooleanBoolean( + final Class claz) { + Constructor cons = getConstructor(claz, + "string-throwable-flags", + String.class, Throwable.class, + Boolean.TYPE, Boolean.TYPE); if (cons == null) { return 0; } @@ -271,20 +291,25 @@ public class ThrowablesTester { } /** - * Tests each combination of values for the "message" and the "cause" when - * using the constructor that takes a String, a Throwable/Exception, and two - * booleans. Verifies that expected values are returned by toString()/i>, + * Tests each combination of values for the "message" and the "cause" + * when using the constructor that takes a String, + * a Throwable/Exception, and two booleans. Verifies that expected + * values are returned + *
      + * toString(), * getMessage(), and getCause(). *
    - * + * * @param cons * constructor to be invoked + * @param to be defined * @throws ConstructionError * if the Throwable subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final void testMessageCauseCombos(Constructor cons) { + public final void testMessageCauseCombos( + final Constructor cons) { T ex; ex = newInstance(cons, null, null, true, true); @@ -309,20 +334,25 @@ public class ThrowablesTester { } /** - * Tests each combination of values for the "message" and the "cause" when - * using the constructor that takes a String, a Throwable/Exception, and two - * booleans. Verifies that expected values are returned by toString()/i>, + * Tests each combination of values for the "message" and the + * "cause" when using the constructor that takes a String, + * a Throwable/Exception, and two booleans. Verifies that + * expected values are returned by + *
      + * toString(), * getMessage(), and getCause(). *
    - * + * * @param cons * constructor to be invoked + * @param to be defined * @throws ConstructionError * if the Throwable subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final void testFlagCombos(Constructor cons) { + public final void testFlagCombos( + final Constructor cons) { testSuppressStack(cons); testSuppressNoStack(cons); testNoSuppressStack(cons); @@ -330,8 +360,9 @@ public class ThrowablesTester { } /** - * Tests Throwable objects constructed with {@code enableSuppression=true} - * and {@code writableStackTrace=true}. Verifies that: + * Tests Throwable objects constructed with + * {@code enableSuppression=true} and + * {@code writableStackTrace=true}. Verifies that: *
      *
    • toString() returns a non-null value
    • *
    • getMessage() returns the original message passed to the @@ -341,15 +372,17 @@ public class ThrowablesTester { *
    • suppressed exceptions are added
    • *
    • the stack trace is added
    • *
    - * + * * @param cons * the throwable's class constructor + * @param to be defined * @throws ConstructionError * if the Throwable subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final void testSuppressStack(Constructor cons) { + public final void testSuppressStack( + final Constructor cons) { T ex = newInstance(cons, "yes,yes", CAUSE, true, true); ex.addSuppressed(SUPPRESSED); @@ -365,8 +398,9 @@ public class ThrowablesTester { } /** - * Tests Throwable objects constructed with {@code enableSuppression=true} - * and {@code writableStackTrace=false}. Verifies that: + * Tests Throwable objects constructed with + * {@code enableSuppression=true} and + * {@code writableStackTrace=false}. Verifies that: *
      *
    • toString() returns a non-null value
    • *
    • getMessage() returns the original message passed to the @@ -376,15 +410,17 @@ public class ThrowablesTester { *
    • suppressed exceptions are added
    • *
    • the stack trace is not added
    • *
    - * + * * @param cons * the throwable's class constructor + * @param to be defined * @throws ConstructionError * if the Throwable subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final void testSuppressNoStack(Constructor cons) { + public final void testSuppressNoStack( + final Constructor cons) { T ex = newInstance(cons, "yes,no", CAUSE, true, false); ex.addSuppressed(SUPPRESSED); @@ -400,8 +436,9 @@ public class ThrowablesTester { } /** - * Tests Throwable objects constructed with {@code enableSuppression=false} - * and {@code writableStackTrace=true}. Verifies that: + * Tests Throwable objects constructed with + * {@code enableSuppression=false} and + * {@code writableStackTrace=true}. Verifies that: *
      *
    • toString() returns a non-null value
    • *
    • getMessage() returns the original message passed to the @@ -411,15 +448,17 @@ public class ThrowablesTester { *
    • suppressed exceptions are not added
    • *
    • the stack trace is added
    • *
    - * + * * @param cons * the throwable's class constructor + * @param to be defined * @throws ConstructionError * if the Throwable subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final void testNoSuppressStack(Constructor cons) { + public final void testNoSuppressStack( + final Constructor cons) { T ex = newInstance(cons, "no,yes", CAUSE, false, true); ex.addSuppressed(SUPPRESSED); @@ -434,8 +473,9 @@ public class ThrowablesTester { } /** - * Tests Throwable objects constructed with {@code enableSuppression=false} - * and {@code writableStackTrace=false}. Verifies that: + * Tests Throwable objects constructed with + * {@code enableSuppression=false} and + * {@code writableStackTrace=false}. Verifies that: *
      *
    • toString() returns a non-null value
    • *
    • getMessage() returns the original message passed to the @@ -444,15 +484,17 @@ public class ThrowablesTester { * constructor
    • *
    • suppressed exceptions are not added
    • *
    • the stack trace is not added
    • - * + *
    * @param cons * the throwable's class constructor + * @param to be defined * @throws ConstructionError * if the Throwable subclass cannot be constructed * @throws AssertionError * if the constructed objects fail to pass various tests */ - public final void testNoSuppressNoStack(Constructor cons) { + public final void testNoSuppressNoStack( + final Constructor cons) { T ex = newInstance(cons, "no,no", CAUSE, false, false); ex.addSuppressed(SUPPRESSED); @@ -467,9 +509,10 @@ public class ThrowablesTester { /** * Attempts to get a constructor for objects of a given type. - * + * * @param claz * class of objects whose constructor is to be gotten + * @param to be defined * @param testType * type of test being run * @param argTypes @@ -477,35 +520,42 @@ public class ThrowablesTester { * @return the desired constructor, or {@code null} if the desired * constructor is not available */ - protected Constructor getConstructor(Class claz, String testType, - Class... argTypes) { + protected Constructor getConstructor( + final Class claz, + final String testType, + final Class... argTypes) { try { return claz.getConstructor(argTypes); } catch (NoSuchMethodException | SecurityException e) { // this constructor is not defined so nothing to test - logger.debug("skipped test, no constructor for: " + claz + " due to: " + e); + logger.debug("skipped test, no constructor for: " + + claz + " due to: " + e); return null; } } /** * Creates a new instance of an Throwable subclass. - * + * * @param cons * subclass constructor + * @param to be defined * @param args * arguments to be passed to the constructor * @return a new instance of the Throwable subclass * @throws ConstructionError * if the Throwable subclass cannot be constructed */ - protected T newInstance(Constructor cons, Object... args) { + protected T newInstance( + final Constructor cons, + final Object... args) { try { return cons.newInstance(args); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + } catch (InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { throw new ConstructionError(e); -- cgit 1.2.3-korg