Fix sonars from dependency upgrade 68/117768/1
authorJim Hahn <jrh3@att.com>
Thu, 11 Feb 2021 23:36:24 +0000 (18:36 -0500)
committerJim Hahn <jrh3@att.com>
Thu, 11 Feb 2021 23:38:49 +0000 (18:38 -0500)
The dependency upgrades in policy-parent caused some new sonars.  In
particular, initMocks() has been deprecated - replaced with calls to the
Mockito Runner.  Also removed unnecessary when() calls.

Issue-ID: POLICY-2912
Change-Id: If386bd282635067a20045f2626af0cf5be49bc0e
Signed-off-by: Jim Hahn <jrh3@att.com>
12 files changed:
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequestTest.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequestTest.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java
main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpHearbeatPublisherTest.java
main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistrationTest.java
main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java
main/src/test/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpStateChangeListenerTest.java
main/src/test/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpUpdateListenerTest.java

index badc5f9..e12a204 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * 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.
@@ -21,8 +21,6 @@ package org.onap.policy.pdp.xacml.application.common.operationshistory;
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.when;
 
 import com.att.research.xacml.api.Attribute;
@@ -49,12 +47,14 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 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.guard.OperationsHistory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@RunWith(MockitoJUnitRunner.class)
 public class CountRecentOperationsPipTest {
     private static final Logger LOGGER = LoggerFactory.getLogger(CountRecentOperationsPipTest.class);
 
@@ -133,8 +133,6 @@ public class CountRecentOperationsPipTest {
      */
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         when(pipRequest.getIssuer()).thenReturn("urn:org:onap:xacml:guard:tw:1:hour");
 
         pipEngine = new MyPip();
@@ -144,16 +142,8 @@ public class CountRecentOperationsPipTest {
             properties.load(is);
         }
 
-        when(pipFinder.getMatchingAttributes(any(), eq(pipEngine))).thenReturn(resp1, resp2, resp3);
-
         responses = new LinkedList<>(Arrays.asList(resp1, resp2, resp3));
         attributes = new LinkedList<>(Arrays.asList(ACTOR, RECIPE, TARGET));
-
-        when(resp1.getStatus()).thenReturn(okStatus);
-        when(resp2.getStatus()).thenReturn(okStatus);
-        when(resp3.getStatus()).thenReturn(okStatus);
-
-        when(okStatus.isOk()).thenReturn(true);
     }
 
     @Test
index dd961d8..61d923c 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * 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.
@@ -45,13 +45,15 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 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.guard.OperationsHistory;
 import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@RunWith(MockitoJUnitRunner.class)
 public class GetOperationOutcomePipTest {
     private static final Logger LOGGER = LoggerFactory.getLogger(GetOperationOutcomePipTest.class);
     private static final String TEST_PROPERTIES = "src/test/resources/test.properties";
@@ -119,8 +121,6 @@ public class GetOperationOutcomePipTest {
      */
     @Before
     public void setupEngine() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         when(pipRequest.getIssuer()).thenReturn("urn:org:onap:xacml:guard:tw:1:hour");
         //
         // Create instance
index 7d7d0e6..be7e0ce 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.
@@ -32,10 +32,12 @@ import java.util.Map;
 import java.util.TreeMap;
 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.models.decisions.concepts.DecisionRequest;
 
+@RunWith(MockitoJUnitRunner.class)
 public class StdCombinedPolicyRequestTest {
     private static final String ACTION = "my-action";
     private static final String ONAP_NAME = "my-name";
@@ -56,8 +58,6 @@ public class StdCombinedPolicyRequestTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         resources = new TreeMap<>();
 
         when(decreq.getResource()).thenReturn(resources);
index f259c20..57ab227 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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,12 +34,14 @@ import java.util.Map;
 import java.util.TreeMap;
 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.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
 import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
 
+@RunWith(MockitoJUnitRunner.class)
 public class StdMatchablePolicyRequestTest {
     private static final String ACTION = "my-action";
     private static final String ONAP_NAME = "my-name";
@@ -62,8 +64,6 @@ public class StdMatchablePolicyRequestTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         resources = new TreeMap<>();
 
         when(decreq.getResource()).thenReturn(resources);
index a0f8573..8234747 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * 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.
@@ -48,10 +48,12 @@ import java.util.Iterator;
 import java.util.Properties;
 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.pdp.xacml.application.common.ToscaDictionary;
 
+@RunWith(MockitoJUnitRunner.class)
 public class StdOnapPipTest {
     private static final String EXPECTED_EXCEPTION = "expected exception";
     private static final String MY_ID = "my-id";
@@ -81,8 +83,6 @@ public class StdOnapPipTest {
      */
     @Before
     public void setUp() throws PIPException {
-        MockitoAnnotations.initMocks(this);
-
         resp = new StdMutablePIPResponse();
 
         when(request.getIssuer()).thenReturn(ISSUER);
index 0552ff3..7d5dd66 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * 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.
@@ -53,8 +53,9 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 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.parameters.RestServerParameters;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
@@ -66,6 +67,7 @@ import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@RunWith(MockitoJUnitRunner.class)
 public class StdXacmlApplicationServiceProviderTest {
     private static final Logger logger = LoggerFactory.getLogger(StdXacmlApplicationServiceProviderTest.class);
 
@@ -131,8 +133,6 @@ public class StdXacmlApplicationServiceProviderTest {
      */
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         policy = new ToscaPolicy();
         policy.setType(POLICY_TYPE);
         policy.setName(POLICY_NAME);
index 8fb7664..8680442 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,12 +29,12 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.util.Arrays;
 import org.junit.AfterClass;
 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.network.NetworkUtil;
 import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
 import org.onap.policy.models.pdp.concepts.PdpStateChange;
@@ -43,10 +43,10 @@ import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.pdp.enums.PdpHealthStatus;
 import org.onap.policy.models.pdp.enums.PdpResponseStatus;
 import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
 import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
 
+@RunWith(MockitoJUnitRunner.class)
 public class XacmlStateTest {
     private static final String PDP_TYPE = "xacml";
     private static final String GROUP = "my-group";
@@ -59,9 +59,6 @@ public class XacmlStateTest {
     @Mock
     private XacmlPdpActivator act;
 
-    private ToscaConceptIdentifier ident1;
-    private ToscaConceptIdentifier ident2;
-
     private String hostName;
 
     private XacmlState state;
@@ -71,15 +68,8 @@ public class XacmlStateTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         hostName = NetworkUtil.getHostname();
 
-        ident1 = new ToscaConceptIdentifier("nameA", "typeA");
-        ident2 = new ToscaConceptIdentifier("nameB", "typeB");
-
-        when(appmgr.getToscaPolicyTypeIdents()).thenReturn(Arrays.asList(ident1, ident2));
-
         XacmlPdpActivator.setCurrent(act);
 
         state = new XacmlState(appmgr, GROUP);
index 550091f..7f90211 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * 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.
@@ -39,12 +39,14 @@ import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 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.client.TopicSinkClient;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.pdpx.main.XacmlState;
 
+@RunWith(MockitoJUnitRunner.class)
 public class XacmlPdpHearbeatPublisherTest {
 
     private static final long INTERVAL1 = 1000L;
@@ -79,8 +81,6 @@ public class XacmlPdpHearbeatPublisherTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         when(state.genHeartbeat()).thenReturn(status);
 
         timers = new LinkedList<>(Arrays.asList(timer1, timer2));
index 9f35f53..9f4d80b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.
@@ -25,12 +25,14 @@ import static org.mockito.Mockito.when;
 
 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.client.TopicSinkClient;
 import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 
+@RunWith(MockitoJUnitRunner.class)
 public class XacmlPdpPapRegistrationTest {
 
     @Mock
@@ -46,8 +48,6 @@ public class XacmlPdpPapRegistrationTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         when(client.send(status)).thenReturn(true);
 
         reg = new XacmlPdpPapRegistration(client);
index c8c6a81..a4cee50 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.
@@ -21,8 +21,8 @@
 package org.onap.policy.pdpx.main.comm;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.startsWith;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.startsWith;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -34,8 +34,9 @@ import java.util.List;
 import java.util.Map;
 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.client.TopicSinkClient;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
@@ -50,6 +51,7 @@ import org.onap.policy.pdpx.main.rest.XacmlPdpStatisticsManager;
 /**
  * Initializes objects, including the publisher.
  */
+@RunWith(MockitoJUnitRunner.class)
 public class XacmlPdpUpdatePublisherTest {
 
     private static final int NEW_COUNT = 4;
@@ -104,8 +106,6 @@ public class XacmlPdpUpdatePublisherTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         Map<ToscaPolicy, XacmlApplicationServiceProvider> deployedPolicies = new HashMap<>();
         deployedPolicies.put(deployed1, null);
         deployedPolicies.put(deployed2, null);
index a1b7e3e..dbc065a 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * 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.
@@ -27,14 +27,16 @@ import static org.mockito.Mockito.when;
 
 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.Topic.CommInfrastructure;
 import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
 import org.onap.policy.models.pdp.concepts.PdpStateChange;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.pdpx.main.XacmlState;
 
+@RunWith(MockitoJUnitRunner.class)
 public class XacmlPdpStateChangeListenerTest {
     private static final String TOPIC = "my-topic";
 
@@ -57,8 +59,6 @@ public class XacmlPdpStateChangeListenerTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         listener = new XacmlPdpStateChangeListener(client, state);
 
         when(state.shouldHandle(change)).thenReturn(true);
index 39ba901..17f71dd 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * 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.
@@ -30,8 +30,9 @@ import static org.mockito.Mockito.when;
 
 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.Topic.CommInfrastructure;
 import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
@@ -41,6 +42,7 @@ import org.onap.policy.pdpx.main.comm.XacmlPdpUpdatePublisher;
 import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
 import org.powermock.reflect.Whitebox;
 
+@RunWith(MockitoJUnitRunner.class)
 public class XacmlPdpUpdateListenerTest {
     private static final String EXPECTED_EXCEPTION = "expected exception";
     private static final String TOPIC = "my-topic";
@@ -70,8 +72,6 @@ public class XacmlPdpUpdateListenerTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         listener = new MyListener(client, state, heartbeat, appmgr);
         update = new PdpUpdate();