From aa987aab348f13d477c6cf32e61689d396ebfba5 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Wed, 8 Jul 2020 13:21:57 +0100 Subject: Fix assertTrue SONAR issues in apex-pdp/examples and apex-pdp/model Replace assertTrue with assertEquals and assertFalse with assertNotEquals in apex-pdp/examples and apex-pdp/model Issue-ID: POLICY-2690 Change-Id: Ie863dd95ccead62268689a4a8388f9b6e8821649 Signed-off-by: JvD_Ericsson --- .../adaptive/AnomalyDetectionConceptTest.java | 26 ++++++++++++---------- .../adaptive/AnomalyDetectionModelTest.java | 5 +++-- .../apex/examples/adaptive/AutoLearnModelTest.java | 5 +++-- 3 files changed, 20 insertions(+), 16 deletions(-) (limited to 'examples/examples-adaptive') diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java index f1c8d7dca..d24733224 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (c) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +24,7 @@ package org.onap.policy.apex.examples.adaptive; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.LinkedList; @@ -65,40 +67,40 @@ public class AnomalyDetectionConceptTest { public void testEquals() { AnomalyDetection anomalyDetection = new AnomalyDetection(); AnomalyDetection comparisonDetection = new AnomalyDetection(); - assertTrue(anomalyDetection.equals(comparisonDetection)); + assertEquals(anomalyDetection, comparisonDetection); //Compare object to itself - assertTrue(anomalyDetection.equals(anomalyDetection)); + assertEquals(anomalyDetection, anomalyDetection); //Compare object to null - assertFalse(anomalyDetection.equals(null)); + assertNotNull(anomalyDetection); //compare object to string - assertFalse(anomalyDetection.equals("test")); + assertNotEquals(anomalyDetection, "test"); // Anomaly Scores comparison anomalyDetection.setAnomalyScores(null); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); comparisonDetection.setAnomalyScores(null); - assertTrue(anomalyDetection.equals(comparisonDetection)); + assertEquals(anomalyDetection, comparisonDetection); List anomalyScores = new LinkedList<>(); anomalyScores.add((double) 20); anomalyDetection.setAnomalyScores(anomalyScores); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); comparisonDetection.setAnomalyScores(anomalyScores); assertTrue(anomalyDetection.checkSetAnomalyScores()); //First Round Checks anomalyDetection.setFirstRound(false); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFirstRound(true); //Frequency Checks anomalyDetection.setFrequency(55); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFrequency(0); //FrequencyForecasted Checks List comparisonFrequency = new LinkedList<>(); comparisonDetection.setFrequencyForecasted(comparisonFrequency); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFrequencyForecasted(anomalyScores); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFrequencyForecasted(comparisonFrequency); - assertTrue(anomalyDetection.equals(comparisonDetection)); + assertEquals(anomalyDetection, comparisonDetection); } @Test diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java index 5a36d4070..85cecbe8b 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.apex.examples.adaptive; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; @@ -44,7 +45,7 @@ public class AnomalyDetectionModelTest { @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); + assertEquals(VALID_MODEL_STRING, result.toString()); } @Test diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java index 1823f9871..3479ccc9e 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.apex.examples.adaptive; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; @@ -44,7 +45,7 @@ public class AutoLearnModelTest { @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); + assertEquals(VALID_MODEL_STRING, result.toString()); } @Test -- cgit 1.2.3-korg