From fb9bd637567096f6174bbc2e52a5e149a4eed882 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 30 Sep 2020 12:52:25 -0400 Subject: Fix new sonars in drools-apps Addressed the following sonars: - too many assertions in test method - rename test class - use static method to modify static field - use already defined constant - code always returns the same value - use assertNotSame - use appropriate class name to access static method - define a constant - extract nested try block - don't always return the same value - use remove() instead of set(null) for thread-local-storage - add @Override Issue-ID: POLICY-2852 Change-Id: Icc62acd4ad57afa2d44ed4cdca504a3ac0810228 Signed-off-by: Jim Hahn --- .../controlloop/eventmanager/ControlLoopEventManager2Drools.java | 2 ++ .../controlloop/eventmanager/ControlLoopOperationManager2.java | 7 ++++++- .../main/java/org/onap/policy/controlloop/eventmanager/Step.java | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'controlloop/common/eventmanager/src/main/java') diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java index 3af9defc7..9e8af9afb 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java @@ -33,6 +33,8 @@ import org.onap.policy.controlloop.drl.legacy.ControlLoopParams; * {@link #isActive()} returns {@code false}, indicating that all steps have completed. */ public class ControlLoopEventManager2Drools extends ControlLoopEventManager2 { + private static final long serialVersionUID = 1L; + private final transient WorkingMemory workMem; private transient FactHandle factHandle; diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java index 31402f4cf..62d4fc8c0 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java @@ -300,7 +300,12 @@ public class ControlLoopOperationManager2 implements Serializable { * @param thrown exception that was generated * @return {@code null} */ - private OperationOutcome handleException(Throwable thrown) { + private OperationOutcome handleException(Throwable thrown) { // NOSONAR + /* + * disabling sonar about returning the same value because we prefer the code to be + * structured this way + */ + if (thrown instanceof CancellationException || thrown.getCause() instanceof CancellationException) { return null; } diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/Step.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/Step.java index ae51c737f..1cbdb53b2 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/Step.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/Step.java @@ -178,7 +178,12 @@ public class Step { * @param thrown exception that was generated * @return {@code null} */ - private OperationOutcome handleException(Throwable thrown) { + private OperationOutcome handleException(Throwable thrown) { // NOSONAR + /* + * disabling sonar about returning the same value because we prefer the code to be + * structured this way + */ + if (thrown instanceof CancellationException || thrown.getCause() instanceof CancellationException) { return null; } -- cgit 1.2.3-korg