diff options
author | Jim Hahn <jrh3@att.com> | 2021-02-12 07:46:30 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-02-12 07:48:37 -0500 |
commit | bcbdb26288e9bd6b1bd0cf8fb2d463d9f49f6333 (patch) | |
tree | 94e8ec8f0d77eae6ab0dd6247b1d79c1fb18a2b7 /main | |
parent | 908406b09093cda33415f8b611482175b32d070c (diff) |
Fix sonars from dependency upgrade
The dependency upgrades in policy-parent caused some new sonars. In
particular, initMocks() has been deprecated - replaced with calls to the
Mockito Runner and one call to openMocks().
Issue-ID: POLICY-2911
Change-Id: I6f28af9af41a1e5c83dead2eabf580731ffb9526
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main')
7 files changed, 22 insertions, 23 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java index 65708aa6..6a0800f1 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java @@ -47,10 +47,11 @@ import javax.ws.rs.core.Response.Status; import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PolicyNotification; import org.onap.policy.models.pap.concepts.PolicyStatus; @@ -71,6 +72,7 @@ import org.onap.policy.pap.main.comm.msgdata.RequestListener; import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams; import org.powermock.reflect.Whitebox; +@RunWith(MockitoJUnitRunner.class) public class PdpModifyRequestMapTest extends CommonRequestBase { private static final String MY_REASON = "my reason"; @@ -117,8 +119,6 @@ public class PdpModifyRequestMapTest extends CommonRequestBase { public void setUp() throws Exception { super.setUp(); - MockitoAnnotations.initMocks(this); - response = new PdpStatus(); update = makeUpdate(PDP1, MY_GROUP, MY_SUBGROUP); @@ -436,8 +436,6 @@ public class PdpModifyRequestMapTest extends CommonRequestBase { PdpGroup group = makeGroup(MY_GROUP); group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP, PDP1))); - when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group)); - invokeLastRetryHandler(1); // should have stopped publishing a second time @@ -692,8 +690,6 @@ public class PdpModifyRequestMapTest extends CommonRequestBase { PdpGroup group = makeGroup(MY_GROUP); group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP, PDP1, DIFFERENT))); - when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group)); - // invoke the method - with a different name (i.e., PDP1 instead of DIFFERENT) invokeSuccessHandler(1); diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpTrackerTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpTrackerTest.java index 2b1e8f1e..ddfed87d 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpTrackerTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpTrackerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -34,10 +34,11 @@ import java.util.List; import java.util.function.Consumer; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; @@ -48,6 +49,7 @@ import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper; import org.onap.policy.pap.main.PolicyPapRuntimeException; import org.onap.policy.pap.main.comm.TimerManager.Timer; +@RunWith(MockitoJUnitRunner.class) public class PdpTrackerTest { private static final String PDP1 = "pdp1"; private static final String PDP2 = "pdp2"; @@ -85,8 +87,6 @@ public class PdpTrackerTest { */ @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - modifyLock = new Object(); builder = PdpTracker.builder().daoFactory(daoFactory).modifyLock(modifyLock).requestMap(requestMap) diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java index e191e02b..8d7a8c15 100644 --- a/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java @@ -34,10 +34,11 @@ import lombok.NonNull; import org.apache.commons.lang3.builder.CompareToBuilder; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PolicyNotification; import org.onap.policy.models.pap.concepts.PolicyStatus; @@ -48,6 +49,7 @@ import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.pap.main.notification.StatusAction.Action; +@RunWith(MockitoJUnitRunner.class) public class DeploymentStatusTest { private static final String VERSION = "1.2.3"; @@ -82,7 +84,6 @@ public class DeploymentStatusTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); tracker = new DeploymentStatus(provider); // @formatter:off diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java index a3665958..9134985c 100644 --- a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java @@ -35,10 +35,11 @@ import java.util.Set; import javax.ws.rs.core.Response.Status; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PolicyNotification; import org.onap.policy.models.pap.concepts.PolicyStatus; @@ -49,6 +50,7 @@ import org.onap.policy.pap.main.PolicyPapRuntimeException; import org.onap.policy.pap.main.comm.Publisher; import org.onap.policy.pap.main.comm.QueueToken; +@RunWith(MockitoJUnitRunner.class) public class PolicyNotifierTest { private static final String GROUP_A = "groupA"; private static final String PDP1 = "pdp-1"; @@ -89,8 +91,6 @@ public class PolicyNotifierTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - try { when(daoFactory.create()).thenReturn(dao); when(dao.getGroupPolicyStatus(anyString())).thenReturn(Collections.emptyList()); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java index 4241b41f..f341b1a9 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java @@ -89,7 +89,7 @@ public class ProviderSuper { Registry.newRegistry(); - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); reqmap = mock(PdpModifyRequestMap.class); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java index 0babb71d..a5f974be 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckProvider.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -33,8 +34,9 @@ import javax.ws.rs.core.Response.Status; import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -54,6 +56,7 @@ import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ +@RunWith(MockitoJUnitRunner.class) public class TestPdpGroupHealthCheckProvider { @Mock @@ -69,7 +72,6 @@ public class TestPdpGroupHealthCheckProvider { public void setUp() throws Exception { Registry.newRegistry(); - MockitoAnnotations.initMocks(this); daofact = mock(PolicyModelsProviderFactoryWrapper.class); when(daofact.create()).thenReturn(dao); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java index ff2159d2..6c707307 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. - * Modifications Copyright (C) 2020 AT&T Corp. + * Modifications Copyright (C) 2020-2021 AT&T Corp. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,8 +38,9 @@ import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; @@ -61,6 +62,7 @@ import org.onap.policy.pap.main.parameters.CommonTestData; import org.onap.policy.pap.main.parameters.PapParameterGroup; import org.onap.policy.pap.main.startstop.PapActivator; +@RunWith(MockitoJUnitRunner.class) public class TestPolicyComponentsHealthCheckProvider { private static final String CLIENT_1 = "client1"; @@ -103,8 +105,6 @@ public class TestPolicyComponentsHealthCheckProvider { */ @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - groups = loadPdpGroupsFromFile().getGroups(); when(dao.getPdpGroups(any())).thenReturn(groups); |