From d879346e830b810eeccf8283fa16e04a9cfafbc8 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Tue, 7 Jul 2020 13:18:20 +0100 Subject: Fix assertTrue SONAR issues in apex-pdp/contex and apex-pdp/core Replace assertTrue with assertEquals and assertFalse with assertNotEquals in apex-pdp/client apex-pdp/context and apex-pdp/core Issue-ID: POLICY-2690 Change-Id: Ic1e69c75e5f8f887cac135b6728b007faf4b19a6 Signed-off-by: JvD_Ericsson --- .../policy/apex/core/engine/event/EnEventTest.java | 20 +++---- .../apex/core/protocols/SupportMessageTester.java | 44 ++++++++-------- .../messages/EngineServiceInfoResponseTest.java | 61 +++++++++++----------- .../protocols/engdep/messages/ResponseTest.java | 33 ++++++------ .../protocols/engdep/messages/UpdateModelTest.java | 32 ++++++------ 5 files changed, 98 insertions(+), 92 deletions(-) (limited to 'core') diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java index e3d0b32b8..225e1853f 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 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. * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -21,7 +22,8 @@ package org.onap.policy.apex.core.engine.event; 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.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -195,14 +197,14 @@ public class EnEventTest { event.clear(); assertNull(event.get("MyField")); - assertTrue(event.hashCode() != 0); + assertNotEquals(0, event.hashCode()); - assertTrue(event.equals(event)); - assertFalse(event.equals(null)); + assertEquals(event, event); + assertNotNull(event); Map hashMap = new HashMap<>(); - assertFalse(event.equals(hashMap)); + assertNotEquals(event, hashMap); EnEvent otherEvent = new EnEvent(eventKey); - assertTrue(event.equals(otherEvent)); + assertEquals(event, otherEvent); } } diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java index 233a1c2ac..925884534 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 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. * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -21,9 +22,8 @@ package org.onap.policy.apex.core.protocols; 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 org.junit.Test; import org.onap.policy.apex.core.protocols.engdep.messages.StartEngine; @@ -58,44 +58,44 @@ public class SupportMessageTester { assertEquals(new AxArtifactKey("Target:0.0.1"), dummyMessage.getTarget()); assertEquals("Target", dummyMessage.getTargetName()); - assertTrue(dummyMessage.hashCode() != 0); + assertNotEquals(0, dummyMessage.hashCode()); dummyMessage.setMessageData(null); - assertTrue(dummyMessage.hashCode() != 0); + assertNotEquals(0, dummyMessage.hashCode()); dummyMessage = new DummyMessage(null, null, null); assertEquals(0, dummyMessage.hashCode()); - assertTrue(dummyMessage.equals(dummyMessage)); - assertFalse(dummyMessage.equals(null)); - assertFalse(dummyMessage.equals(new StartEngine(new AxArtifactKey()))); + assertEquals(dummyMessage, dummyMessage); + assertNotNull(dummyMessage); + assertNotEquals(dummyMessage, new StartEngine(new AxArtifactKey())); dummyMessage = new DummyMessage(new DummyAction(null), null, null); DummyMessage otherDummyMessage = new DummyMessage(null, null, null); - assertFalse(dummyMessage.equals(otherDummyMessage)); + assertNotEquals(dummyMessage, otherDummyMessage); otherDummyMessage = new DummyMessage(new DummyAction(null), null, null); - assertTrue(dummyMessage.equals(otherDummyMessage)); + assertEquals(dummyMessage, otherDummyMessage); dummyMessage = new DummyMessage(null, null, null); - assertFalse(dummyMessage.equals(otherDummyMessage)); + assertNotEquals(dummyMessage, otherDummyMessage); otherDummyMessage = new DummyMessage(null, null, null); - assertTrue(dummyMessage.equals(otherDummyMessage)); + assertEquals(dummyMessage, otherDummyMessage); dummyMessage = new DummyMessage(null, new AxArtifactKey(), null); otherDummyMessage = new DummyMessage(null, null, null); - assertFalse(dummyMessage.equals(otherDummyMessage)); + assertNotEquals(dummyMessage, otherDummyMessage); otherDummyMessage = new DummyMessage(null, new AxArtifactKey(), null); - assertTrue(dummyMessage.equals(otherDummyMessage)); + assertEquals(dummyMessage, otherDummyMessage); dummyMessage = new DummyMessage(null, null, null); - assertFalse(dummyMessage.equals(otherDummyMessage)); + assertNotEquals(dummyMessage, otherDummyMessage); otherDummyMessage = new DummyMessage(null, null, null); - assertTrue(dummyMessage.equals(otherDummyMessage)); + assertEquals(dummyMessage, otherDummyMessage); dummyMessage = new DummyMessage(null, null, "Message"); otherDummyMessage = new DummyMessage(null, null, null); - assertFalse(dummyMessage.equals(otherDummyMessage)); + assertNotEquals(dummyMessage, otherDummyMessage); otherDummyMessage = new DummyMessage(null, null, "Message"); - assertTrue(dummyMessage.equals(otherDummyMessage)); + assertEquals(dummyMessage, otherDummyMessage); dummyMessage = new DummyMessage(null, null, null); - assertFalse(dummyMessage.equals(otherDummyMessage)); + assertNotEquals(dummyMessage, otherDummyMessage); otherDummyMessage = new DummyMessage(null, null, null); - assertTrue(dummyMessage.equals(otherDummyMessage)); + assertEquals(dummyMessage, otherDummyMessage); } } diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponseTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponseTest.java index c240704e9..87fe44aae 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponseTest.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponseTest.java @@ -1,20 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -22,9 +22,8 @@ package org.onap.policy.apex.core.protocols.engdep.messages; 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.ArrayList; import java.util.List; @@ -40,72 +39,72 @@ public class EngineServiceInfoResponseTest { public void test() { AxArtifactKey targetKey = new AxArtifactKey("Target:0.0.1"); GetEngineServiceInfo request = new GetEngineServiceInfo(targetKey); - + EngineServiceInfoResponse response = new EngineServiceInfoResponse(targetKey, true, request); assertNotNull(response); response = new EngineServiceInfoResponse(targetKey, true, "Response Data", request); assertNotNull(response); assertEquals("Response Data", response.getMessageData()); - + AxArtifactKey apexModelKey = new AxArtifactKey("Model:0.0.1"); response.setApexModelKey(apexModelKey); assertEquals(apexModelKey, response.getApexModelKey()); - + AxArtifactKey engineServiceKey = new AxArtifactKey("EngineService:0.0.1"); response.setEngineServiceKey(engineServiceKey);; assertEquals(engineServiceKey, response.getEngineServiceKey()); - + List engineKeyArrayList = new ArrayList<>(); AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1"); engineKeyArrayList.add(engineKey); response.setEngineKeyArray(engineKeyArrayList); assertEquals(engineKeyArrayList.get(0), response.getEngineKeyArray()[0]); - + response = new EngineServiceInfoResponse(null, false, null); - assertTrue(response.hashCode() != 0); + assertNotEquals(0, response.hashCode()); response.setApexModelKey(apexModelKey); - assertTrue(response.hashCode() != 0); + assertNotEquals(0, response.hashCode()); response.setApexModelKey(null); response.setEngineServiceKey(engineServiceKey);; - assertTrue(response.hashCode() != 0); + assertNotEquals(0, response.hashCode()); response.setEngineServiceKey(null); response.setEngineKeyArray(engineKeyArrayList); - assertTrue(response.hashCode() != 0); + assertNotEquals(0, response.hashCode()); response.setEngineKeyArray(null); - - assertTrue(response.equals(response)); - assertFalse(response.equals(null)); - assertFalse(response.equals((Object) new StartEngine(new AxArtifactKey()))); + + assertEquals(response, response); + assertNotNull(response); + assertNotEquals(response, (Object) new StartEngine(new AxArtifactKey())); response = new EngineServiceInfoResponse(null, false, null); EngineServiceInfoResponse otherResponse = new EngineServiceInfoResponse(null, false, null); response.setApexModelKey(apexModelKey); - assertFalse(response.equals(otherResponse)); + assertNotEquals(response, otherResponse); otherResponse.setApexModelKey(apexModelKey); - assertTrue(response.equals(otherResponse)); + assertEquals(response, otherResponse); response.setApexModelKey(null); - assertFalse(response.equals(otherResponse)); + assertNotEquals(response, otherResponse); otherResponse.setApexModelKey(null); - assertTrue(response.equals(otherResponse)); + assertEquals(response, otherResponse); response.setEngineServiceKey(engineServiceKey); - assertFalse(response.equals(otherResponse)); + assertNotEquals(response, otherResponse); otherResponse.setEngineServiceKey(engineServiceKey); - assertTrue(response.equals(otherResponse)); + assertEquals(response, otherResponse); response.setEngineServiceKey(null); - assertFalse(response.equals(otherResponse)); + assertNotEquals(response, otherResponse); otherResponse.setEngineServiceKey(null); - assertTrue(response.equals(otherResponse)); + assertEquals(response, otherResponse); response.setEngineKeyArray(engineKeyArrayList); - assertFalse(response.equals(otherResponse)); + assertNotEquals(response, otherResponse); otherResponse.setEngineKeyArray(engineKeyArrayList); - assertTrue(response.equals(otherResponse)); + assertEquals(response, otherResponse); response.setEngineKeyArray(null); - assertFalse(response.equals(otherResponse)); + assertNotEquals(response, otherResponse); otherResponse.setEngineKeyArray(null); - assertTrue(response.equals(otherResponse)); + assertEquals(response, otherResponse); } } diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/ResponseTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/ResponseTest.java index 2c1f658b3..b28993a41 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/ResponseTest.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/ResponseTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019-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. @@ -22,6 +23,8 @@ package org.onap.policy.apex.core.protocols.engdep.messages; 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.net.UnknownHostException; @@ -63,32 +66,32 @@ public class ResponseTest { assertEquals(responseTo, message.getResponseTo()); message = new Response(null, false, null); - assertTrue(message.hashCode() != 0); + assertNotEquals(0, message.hashCode()); message = new Response(responseKey, false, null); - assertTrue(message.hashCode() != 0); + assertNotEquals(0, message.hashCode()); message = new Response(responseKey, true, null); - assertTrue(message.hashCode() != 0); + assertNotEquals(0, message.hashCode()); message = new Response(responseKey, true, new UpdateModel(null)); - assertTrue(message.hashCode() != 0); - - assertTrue(message.equals(message)); - assertFalse(message.equals(null)); - assertFalse(message.equals(new StartEngine(new AxArtifactKey()))); + assertNotEquals(0, message.hashCode()); + + assertEquals(message, message); + assertNotNull(message); + assertNotEquals(message, new StartEngine(new AxArtifactKey())); message = new Response(null, false, responseTo); Response otherMessage = new Response(null, false, null); - assertFalse(message.equals(otherMessage)); + assertNotEquals(message, otherMessage); otherMessage = new Response(null, false, responseTo); - assertTrue(message.equals(otherMessage)); + assertEquals(message, otherMessage); message = new Response(null, false, null); - assertFalse(message.equals(otherMessage)); + assertNotEquals(message, otherMessage); otherMessage = new Response(null, false, null); - assertTrue(message.equals(otherMessage)); - + assertEquals(message, (otherMessage)); + message = new Response(null, false, null); otherMessage = new Response(null, true, null); - assertFalse(message.equals(otherMessage)); + assertNotEquals(message, otherMessage); otherMessage = new Response(null, false, null); - assertTrue(message.equals(otherMessage)); + assertEquals(message, otherMessage); } } diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModelTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModelTest.java index 9f954b5a5..0839a43b8 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModelTest.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModelTest.java @@ -20,7 +20,9 @@ package org.onap.policy.apex.core.protocols.engdep.messages; +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; @@ -57,30 +59,30 @@ public class UpdateModelTest { assertTrue((message.toString()).contains("Placeholder for Apex model XML")); assertFalse(message.isIgnoreConflicts()); assertFalse(message.isForceInstall()); - + message = new UpdateModel(null, null, false, false); - assertTrue(message.hashCode() != 0); + assertNotEquals(0, message.hashCode()); message = new UpdateModel(null, null, true, false); - assertTrue(message.hashCode() != 0); + assertNotEquals(0, message.hashCode()); message = new UpdateModel(null, null, true, true); - assertTrue(message.hashCode() != 0); + assertNotEquals(0, message.hashCode()); message = new UpdateModel(null, null, false, true); - assertTrue(message.hashCode() != 0); - - assertTrue(message.equals(message)); - assertFalse(message.equals(null)); - assertFalse(message.equals(new StartEngine(new AxArtifactKey()))); - + assertNotEquals(0, message.hashCode()); + + assertEquals(message, message); + assertNotNull(message); + assertNotEquals(message, new StartEngine(new AxArtifactKey())); + message = new UpdateModel(null, null, false, false); UpdateModel otherMessage = new UpdateModel(null, null, false, false); - assertTrue(message.equals(otherMessage)); + assertEquals(message, otherMessage); message = new UpdateModel(null, null, true, false); - assertFalse(message.equals(otherMessage)); + assertNotEquals(message, otherMessage); otherMessage = new UpdateModel(null, null, true, false); - assertTrue(message.equals(otherMessage)); + assertEquals(message, otherMessage); message = new UpdateModel(null, null, false, true); - assertFalse(message.equals(otherMessage)); + assertNotEquals(message, otherMessage); otherMessage = new UpdateModel(null, null, false, true); - assertTrue(message.equals(otherMessage)); + assertEquals(message, otherMessage); } } -- cgit 1.2.3-korg