From 57c87591cde427a672dcbeb17f17eb06fbdeca1c Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 29 Jun 2020 12:14:07 -0400 Subject: Fix issues in api for new sonar rules Addressed issues reported due to updates to the sonar rules: - use assertEquals, assertNull, etc. - use "<>" - use "{}" place-holder Issue-ID: POLICY-2680 Change-Id: I42d5e635e09bac6e520fc7aa386814ad617fc1f6 Signed-off-by: Jim Hahn --- .../org/onap/policy/api/main/rest/TestCommonRestController.java | 6 +++--- .../main/rest/provider/TestLegacyOperationalPolicyProvider.java | 3 +-- .../test/java/org/onap/policy/api/main/startstop/TestMain.java | 9 +++++---- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'main/src/test/java/org/onap') diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java index 68377003..dc921488 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ package org.onap.policy.api.main.rest; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertSame; import java.util.UUID; import javax.ws.rs.core.Response; @@ -42,7 +42,7 @@ public class TestCommonRestController { UUID requestId = UUID.randomUUID(); ResponseBuilder rb = crc.addLoggingHeaders(crc.addVersionControlHeaders(Response.status(Response.Status.OK)), requestId); - assertTrue(rb.equals(rb.header("X-ONAP-RequestID", requestId))); + assertSame(rb, rb.header("X-ONAP-RequestID", requestId)); } /* diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java index bb4eca95..c91d8adc 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java @@ -26,7 +26,6 @@ package org.onap.policy.api.main.rest.provider; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -222,7 +221,7 @@ public class TestLegacyOperationalPolicyProvider { operationalPolicyProvider.createOperationalPolicy(policyToCreate); assertEquals("operational.restart", policyCreated.getPolicyId()); assertEquals("1", policyCreated.getPolicyVersion()); - assertFalse(policyCreated.getContent() == null); + assertNotNull(policyCreated.getContent()); }).doesNotThrowAnyException(); // Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java index 60222f6d..90397755 100644 --- a/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java +++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 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. @@ -23,6 +23,7 @@ package org.onap.policy.api.main.startstop; import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -51,14 +52,14 @@ public class TestMain { public void testMain_NoArguments() { final String[] apiConfigParameters = {}; final Main main = new Main(apiConfigParameters); - assertTrue(main.getParameters() == null); + assertNull(main.getParameters()); } @Test public void testMain_InvalidArguments() { final String[] apiConfigParameters = {"parameters/ApiConfigParameters.json"}; final Main main = new Main(apiConfigParameters); - assertTrue(main.getParameters() == null); + assertNull(main.getParameters()); } @Test @@ -71,6 +72,6 @@ public class TestMain { public void testMain_InvalidParameters() { final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidName.json"}; final Main main = new Main(apiConfigParameters); - assertTrue(main.getParameters() == null); + assertNull(main.getParameters()); } } -- cgit 1.2.3-korg