Cleanup use of deprecated constructs 53/89953/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 May 2020 10:53:31 +0000 (12:53 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 26 May 2020 11:09:25 +0000 (13:09 +0200)
A number of tests are reporting use of deprecated methods, this patch
cleans some of them up.

Change-Id: Ibbaa87be60a2b9261e473df040c3738cae8181d9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
19 files changed:
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/ValidateTest.java
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscriptionTest.java
netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java
netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java
netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/xml/XmlElementTest.java
netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/SimpleNetconfClientSessionListenerTest.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSessionTest.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/util/DeserializerExceptionHandlerTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfHelloMessageToXMLEncoderTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoderTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/NetconfUtilTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/LibraryModulesSchemasTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfSessionPreferencesTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOpsTest.java

index 2b95d65299390908aeb49fca9c976cf73281bc0e..ac84a0c8aa3f18bfe467df72b355b5feb0237517 100644 (file)
@@ -12,8 +12,6 @@ import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.MockitoAnnotations.initMocks;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
 
@@ -27,11 +25,14 @@ import org.custommonkey.xmlunit.DetailedDiff;
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;
 import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
+import org.junit.After;
 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.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
 import org.opendaylight.mdsal.dom.api.DOMRpcException;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
@@ -69,6 +70,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class RuntimeRpcTest {
     private static final Logger LOG = LoggerFactory.getLogger(RuntimeRpcTest.class);
     private static final String SESSION_ID_FOR_REPORTING = "netconf-test-session1";
@@ -159,11 +161,7 @@ public class RuntimeRpcTest {
 
     @Before
     public void setUp() throws Exception {
-        initMocks(this);
         doNothing().when(registration).close();
-        doReturn(listener).when(registration).getInstance();
-        doReturn(null).when(schemaService).getGlobalContext();
-        doReturn(null).when(schemaService).getSessionContext();
         doAnswer(invocationOnMock -> {
             ((EffectiveModelContextListener) invocationOnMock.getArguments()[0]).onModelContextUpdated(SCHEMA_CONTEXT);
             return registration;
@@ -182,6 +180,11 @@ public class RuntimeRpcTest {
         this.currentSchemaContext = new CurrentSchemaContext(schemaService, sourceProvider);
     }
 
+    @After
+    public void tearDown() {
+        currentSchemaContext.close();
+    }
+
     @Test
     public void testVoidOutputRpc() throws Exception {
         final RuntimeRpc rpc = new RuntimeRpc(SESSION_ID_FOR_REPORTING, currentSchemaContext, RPC_SERVICE_VOID_INVOKER);
index 1ec8d2e2ebdd90f649cba250d48f86e250c43774..49af75c0c8b4d8a4e135df1e8648b24391218830 100644 (file)
@@ -8,12 +8,11 @@
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.MockitoAnnotations.initMocks;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.opendaylight.netconf.mdsal.connector.ops.AbstractNetconfOperationTest.RPC_REPLY_OK;
 import static org.opendaylight.netconf.mdsal.connector.ops.AbstractNetconfOperationTest.SESSION_ID_FOR_REPORTING;
 import static org.opendaylight.netconf.mdsal.connector.ops.AbstractNetconfOperationTest.executeOperation;
@@ -23,7 +22,9 @@ import com.google.common.collect.ImmutableClassToInstanceMap;
 import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.netconf.api.DocumentedException;
@@ -33,6 +34,7 @@ import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.w3c.dom.Document;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ValidateTest {
     @Mock
     private DOMDataTransactionValidator noopValidator;
@@ -44,8 +46,7 @@ public class ValidateTest {
     private DOMDataBroker dataBroker;
 
     @Before
-    public void setUp() throws Exception {
-        initMocks(this);
+    public void setUp() {
         doReturn(FluentFutures.immediateNullFluentFuture()).when(noopValidator).validate(any());
         doReturn(FluentFutures.immediateFailedFluentFuture(new ValidationFailedException("invalid data")))
             .when(failingValidator).validate(any());
@@ -56,47 +57,38 @@ public class ValidateTest {
     @Test
     public void testValidateUnsupported() throws Exception {
         whenValidatorIsNotDefined();
-        try {
-            validate("messages/mapping/validate/validate.xml");
-            fail("Should have failed - <validate> not supported");
-        } catch (final DocumentedException e) {
-            assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
-            assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
-            assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
-        }
+        final DocumentedException e = assertThrows(DocumentedException.class,
+            () -> validate("messages/mapping/validate/validate.xml"));
+        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
+        assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
     }
 
     @Test
     public void testSourceMissing() throws Exception {
         whenUsingValidator(noopValidator);
-        try {
-            validate("messages/mapping/validate/validate_no_source.xml");
-            fail("Should have failed - <source> element is missing");
-        } catch (final DocumentedException e) {
-            assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
-            assertEquals(DocumentedException.ErrorTag.MISSING_ELEMENT, e.getErrorTag());
-            assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
-        }
+        final DocumentedException e = assertThrows(DocumentedException.class,
+            () -> validate("messages/mapping/validate/validate_no_source.xml"));
+        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(DocumentedException.ErrorTag.MISSING_ELEMENT, e.getErrorTag());
+        assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
     }
 
     @Test
     public void testSourceRunning() throws Exception {
         whenUsingValidator(noopValidator);
-        try {
-            validate("messages/mapping/validate/validate_running.xml");
-            fail("Should have failed - <running/> is not supported");
-        } catch (final DocumentedException e) {
-            assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
-            assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
-            assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
-        }
+        final DocumentedException e = assertThrows(DocumentedException.class,
+            () -> validate("messages/mapping/validate/validate_running.xml"));
+        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
+        assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
     }
 
     @Test
     public void testValidateEmptyTx() throws Exception {
         whenUsingValidator(noopValidator);
         verifyResponse(validate("messages/mapping/validate/validate.xml"), RPC_REPLY_OK);
-        verifyZeroInteractions(noopValidator);
+        verifyNoMoreInteractions(noopValidator);
     }
 
     @Test
@@ -111,14 +103,11 @@ public class ValidateTest {
     public void testValidateFailed() throws Exception {
         whenUsingValidator(failingValidator);
         final TransactionProvider transactionProvider = initCandidateTransaction();
-        try {
-            validate("messages/mapping/validate/validate.xml", transactionProvider);
-            fail("Should have failed - operation failed");
-        } catch (final DocumentedException e) {
-            assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
-            assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, e.getErrorTag());
-            assertEquals(DocumentedException.ErrorType.APPLICATION, e.getErrorType());
-        }
+        final DocumentedException e = assertThrows(DocumentedException.class,
+            () -> validate("messages/mapping/validate/validate.xml", transactionProvider));
+        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, e.getErrorTag());
+        assertEquals(DocumentedException.ErrorType.APPLICATION, e.getErrorType());
     }
 
     private void whenValidatorIsNotDefined() {
@@ -136,7 +125,8 @@ public class ValidateTest {
         return transactionProvider;
     }
 
-    private Document validate(final String resource,  final TransactionProvider transactionProvider) throws Exception {
+    private static Document validate(final String resource,  final TransactionProvider transactionProvider)
+            throws Exception {
         final Validate validate = new Validate(SESSION_ID_FOR_REPORTING, transactionProvider);
         return executeOperation(validate, resource);
     }
index e24ef4f67d42c853a4285c5e05679b865e74c817..329c274fa7167192bc7f20b6f8bff0da37663d51 100644 (file)
@@ -5,19 +5,19 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.notification.impl.ops;
 
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
-import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
 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.opendaylight.netconf.api.NetconfSession;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -27,6 +27,7 @@ import org.opendaylight.netconf.notifications.NotificationListenerRegistration;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
 import org.w3c.dom.Element;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class CreateSubscriptionTest {
 
     private static final String CREATE_SUBSCRIPTION_XML = "<create-subscription\n"
@@ -39,8 +40,7 @@ public class CreateSubscriptionTest {
     private NetconfNotificationRegistry notificationRegistry;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void setUp() {
         doReturn(true).when(notificationRegistry).isStreamAvailable(any(StreamNameType.class));
         doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry)
                 .registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
@@ -57,6 +57,6 @@ public class CreateSubscriptionTest {
         final Element element =
                 createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
 
-        Assert.assertThat(XmlUtil.toString(element), CoreMatchers.containsString("ok"));
+        assertThat(XmlUtil.toString(element), containsString("ok"));
     }
 }
index b6ab7fe86a8e50836bd926018d56ef0f07815b22..0644d52d68343bc4672cf0c4fcab12f30f04483f 100644 (file)
@@ -5,21 +5,24 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
 import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.verify;
 
 import java.util.Collection;
 import java.util.Set;
 import javax.xml.transform.dom.DOMSource;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
@@ -27,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.even
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ConnectionNotificationTopicRegistrationTest {
 
     private ConnectionNotificationTopicRegistration registration;
@@ -35,8 +39,7 @@ public class ConnectionNotificationTopicRegistrationTest {
     private DOMNotificationListener listener;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void setUp() {
         registration = new ConnectionNotificationTopicRegistration("candidate", listener);
     }
 
@@ -44,7 +47,7 @@ public class ConnectionNotificationTopicRegistrationTest {
     public void testClose() throws Exception {
         registration.setActive(true);
         registration.close();
-        Assert.assertFalse(registration.isActive());
+        assertFalse(registration.isActive());
         checkStatus(listener, EventSourceStatus.Deactive);
     }
 
@@ -73,15 +76,15 @@ public class ConnectionNotificationTopicRegistrationTest {
         final TopicId topic3 = registerTopic("topic3");
         final Set<TopicId> notificationTopicIds =
                 registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH);
-        Assert.assertNotNull(notificationTopicIds);
-        Assert.assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
+        assertNotNull(notificationTopicIds);
+        assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
 
         registration.unRegisterNotificationTopic(topic3);
         final Set<TopicId> afterUnregister =
                 registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH);
-        Assert.assertNotNull(afterUnregister);
-        Assert.assertThat(afterUnregister, hasItems(topic1, topic2));
-        Assert.assertFalse(afterUnregister.contains(topic3));
+        assertNotNull(afterUnregister);
+        assertThat(afterUnregister, hasItems(topic1, topic2));
+        assertFalse(afterUnregister.contains(topic3));
     }
 
     private TopicId registerTopic(final String value) {
@@ -101,12 +104,12 @@ public class ConnectionNotificationTopicRegistrationTest {
         ArgumentCaptor<DOMNotification> notificationCaptor = ArgumentCaptor.forClass(DOMNotification.class);
         verify(listener).onNotification(notificationCaptor.capture());
         final DOMNotification value = notificationCaptor.getValue();
-        Assert.assertEquals(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH, value.getType());
+        assertEquals(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH, value.getType());
         final Collection<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> body = value.getBody()
                 .getValue();
-        Assert.assertEquals(1, body.size());
+        assertEquals(1, body.size());
         final DOMSource source = (DOMSource) body.iterator().next().getValue();
         final String statusNodeValue = source.getNode().getFirstChild().getFirstChild().getNodeValue();
-        Assert.assertEquals(status.toString(), statusNodeValue);
+        assertEquals(status.toString(), statusNodeValue);
     }
 }
\ No newline at end of file
index 1b4ee18606da6cfe404c383c18ee85a2a3e446dc..1ea0410d8d9e928220c9a709705e2e0d7af2431e 100644 (file)
@@ -8,6 +8,10 @@
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
 import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
@@ -17,11 +21,11 @@ import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediate
 import java.time.Instant;
 import java.util.Optional;
 import java.util.Set;
-import org.junit.Assert;
 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.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
@@ -33,6 +37,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class StreamNotificationTopicRegistrationTest {
 
     private static final String STREAM_NAME = "stream-1";
@@ -53,8 +58,6 @@ public class StreamNotificationTopicRegistrationTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         Node node = new NodeBuilder().setNodeId(NodeId.getDefaultInstance("node-id")).build();
         when(mount.getNode()).thenReturn(node);
         when(mount.registerNotificationListener(source, ConnectionNotificationTopicRegistration
@@ -73,7 +76,7 @@ public class StreamNotificationTopicRegistrationTest {
     @Test
     public void testActivateNotificationSource() throws Exception {
         registration.activateNotificationSource();
-        Assert.assertTrue(registration.isActive());
+        assertTrue(registration.isActive());
         verify(mount).invokeCreateSubscription(stream);
 
     }
@@ -83,7 +86,7 @@ public class StreamNotificationTopicRegistrationTest {
         registration.setActive(true);
         registration.reActivateNotificationSource();
 
-        Assert.assertTrue(registration.isActive());
+        assertTrue(registration.isActive());
         verify(mount).invokeCreateSubscription(stream, Optional.empty());
     }
 
@@ -94,7 +97,7 @@ public class StreamNotificationTopicRegistrationTest {
         registration.setLastEventTime(lastEventTime);
         registration.reActivateNotificationSource();
 
-        Assert.assertTrue(registration.isActive());
+        assertTrue(registration.isActive());
         verify(mount).invokeCreateSubscription(stream, Optional.of(lastEventTime));
     }
 
@@ -102,7 +105,7 @@ public class StreamNotificationTopicRegistrationTest {
     public void testClose() throws Exception {
         registration.setActive(true);
         registration.close();
-        Assert.assertFalse(registration.isActive());
+        assertFalse(registration.isActive());
     }
 
     @Test
@@ -112,15 +115,15 @@ public class StreamNotificationTopicRegistrationTest {
         final TopicId topic3 = registerTopic("topic3");
         final Set<TopicId> notificationTopicIds =
                 registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH);
-        Assert.assertNotNull(notificationTopicIds);
-        Assert.assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
+        assertNotNull(notificationTopicIds);
+        assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
 
         registration.unRegisterNotificationTopic(topic3);
         final Set<TopicId> afterUnregister =
                 registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH);
-        Assert.assertNotNull(afterUnregister);
-        Assert.assertThat(afterUnregister, hasItems(topic1, topic2));
-        Assert.assertFalse(afterUnregister.contains(topic3));
+        assertNotNull(afterUnregister);
+        assertThat(afterUnregister, hasItems(topic1, topic2));
+        assertFalse(afterUnregister.contains(topic3));
     }
 
     private TopicId registerTopic(final String value) {
index f529ed5492e5a1c1996fb5e52fecae357b458b5d..04c73da365986035aca402c6b299a129826324bd 100644 (file)
@@ -9,14 +9,14 @@ package org.opendaylight.netconf.api.xml;
 
 import static org.hamcrest.CoreMatchers.both;
 import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
@@ -51,26 +51,10 @@ public class XmlElementTest {
         XmlElement.fromDomElementWithExpected(element, "top");
         XmlElement.fromDomElementWithExpected(element, "top", "namespace");
 
-        try {
-            XmlElement.fromString("notXml");
-            fail();
-        } catch (final DocumentedException e) {
-            // expected
-        }
-
-        try {
-            XmlElement.fromDomElementWithExpected(element, "notTop");
-            fail();
-        } catch (final DocumentedException e) {
-            // expected
-        }
-
-        try {
-            XmlElement.fromDomElementWithExpected(element, "top", "notNamespace");
-            fail();
-        } catch (final DocumentedException e) {
-            // expected
-        }
+        assertThrows(DocumentedException.class, () -> XmlElement.fromString("notXml"));
+        assertThrows(DocumentedException.class, () -> XmlElement.fromDomElementWithExpected(element, "notTop"));
+        assertThrows(DocumentedException.class,
+            () -> XmlElement.fromDomElementWithExpected(element, "top", "notNamespace"));
     }
 
     @Test
@@ -103,12 +87,8 @@ public class XmlElementTest {
 
         final XmlElement noNamespaceElement = XmlElement.fromString("<noNamespace/>");
         assertFalse(noNamespaceElement.hasNamespace());
-        try {
-            noNamespaceElement.getNamespace();
-            fail();
-        } catch (final MissingNameSpaceException e) {
-            // expected
-        }
+
+        assertThrows(MissingNameSpaceException.class, () -> noNamespaceElement.getNamespace());
 
         final XmlElement inner = xmlElement.getOnlyChildElement("inner");
         final XmlElement deepInner = inner.getOnlyChildElementWithSameNamespaceOptionally().get();
@@ -122,7 +102,7 @@ public class XmlElementTest {
     @Test
     public void testExtractNamespaces() throws Exception {
         final XmlElement innerPrefixed = xmlElement.getOnlyChildElement("innerPrefixed");
-        Map.Entry<String, String> namespaceOfTextContent = innerPrefixed.findNamespaceOfTextContent();
+        Entry<String, String> namespaceOfTextContent = innerPrefixed.findNamespaceOfTextContent();
 
         assertNotNull(namespaceOfTextContent);
         assertEquals("b", namespaceOfTextContent.getKey());
@@ -139,11 +119,8 @@ public class XmlElementTest {
         xmlElement.checkUnrecognisedElements(xmlElement.getOnlyChildElement("inner"),
                 xmlElement.getOnlyChildElement("innerPrefixed"), xmlElement.getOnlyChildElement("innerNamespace"));
 
-        try {
-            xmlElement.checkUnrecognisedElements(xmlElement.getOnlyChildElement("inner"));
-            fail();
-        } catch (final DocumentedException e) {
-            assertThat(e.getMessage(), both(containsString("innerNamespace")).and(containsString("innerNamespace")));
-        }
+        final DocumentedException e = assertThrows(DocumentedException.class,
+            () -> xmlElement.checkUnrecognisedElements(xmlElement.getOnlyChildElement("inner")));
+        assertThat(e.getMessage(), both(containsString("innerNamespace")).and(containsString("innerNamespace")));
     }
 }
index 133eef6bf022b507fdc6c0827e4293b7e6920b5e..60f3ad89e1a29fb9acfea45265e3dc4da8243351 100644 (file)
@@ -5,13 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.client;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyObject;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -47,8 +45,8 @@ public class SimpleNetconfClientSessionListenerTest {
         channelFuture = mock(ChannelPromise.class);
         mockEventLoop();
         doReturn(channelFuture).when(channel).newPromise();
-        doReturn(channelFuture).when(channel).writeAndFlush(anyObject());
-        doReturn(channelFuture).when(channel).writeAndFlush(anyObject(), any(ChannelPromise.class));
+        doReturn(channelFuture).when(channel).writeAndFlush(any());
+        doReturn(channelFuture).when(channel).writeAndFlush(any(), any(ChannelPromise.class));
         doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
         caps = Sets.newSet("a", "b");
         helloMessage = NetconfHelloMessage.createServerHello(caps, 10);
@@ -71,7 +69,7 @@ public class SimpleNetconfClientSessionListenerTest {
         SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
         final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
         simpleListener.onSessionUp(clientSession);
-        verify(channel, times(1)).writeAndFlush(anyObject(), anyObject());
+        verify(channel, times(1)).writeAndFlush(any(), any());
 
         simpleListener.onSessionDown(clientSession, new Exception());
         assertFalse(promise.isSuccess());
@@ -82,7 +80,7 @@ public class SimpleNetconfClientSessionListenerTest {
         SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
         final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
         simpleListener.onSessionUp(clientSession);
-        verify(channel, times(1)).writeAndFlush(anyObject(), anyObject());
+        verify(channel, times(1)).writeAndFlush(any(), any());
 
         simpleListener.sendRequest(message);
         assertFalse(promise.isSuccess());
@@ -93,7 +91,7 @@ public class SimpleNetconfClientSessionListenerTest {
         SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
         final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
         simpleListener.onSessionUp(clientSession);
-        verify(channel, times(1)).writeAndFlush(anyObject(), anyObject());
+        verify(channel, times(1)).writeAndFlush(any(), any());
 
         simpleListener.onMessage(clientSession, message);
         assertTrue(promise.isSuccess());
index deddd88033b2cb765d6b9f88e285052782dc3a34..dcc768374e10e84efc3deeb2f0a006a72f21c670 100644 (file)
@@ -5,11 +5,9 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.impl.mapping.operations;
 
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyObject;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
@@ -66,7 +64,7 @@ public class DefaultCloseSessionTest {
             return null;
         }).when(sendFuture).addListener(any(GenericFutureListener.class));
         doReturn(sendFuture).when(channel).newPromise();
-        doReturn(sendFuture).when(channel).writeAndFlush(anyObject(), anyObject());
+        doReturn(sendFuture).when(channel).writeAndFlush(any(), any());
         doReturn(true).when(sendFuture).isSuccess();
         final NetconfServerSessionListener listener = mock(NetconfServerSessionListener.class);
         doNothing().when(listener).onSessionTerminated(any(NetconfServerSession.class),
index ec98700a104a6fc8e000180e4433d423c5bfe18e..91f0b5451d668284eeff6f752f886a235e057f05 100644 (file)
@@ -5,11 +5,9 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.impl.util;
 
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyObject;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
@@ -37,7 +35,7 @@ public class DeserializerExceptionHandlerTest {
         doReturn(channel).when(context).channel();
         channelFuture = mock(ChannelFuture.class);
         doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
-        doReturn(channelFuture).when(channel).writeAndFlush(anyObject());
+        doReturn(channelFuture).when(channel).writeAndFlush(any());
     }
 
     @Test
index e3d152c2659a70a5a04a13fc60ee596c574497eb..5cd450edada743eb0e7774769e50b00400039b9d 100644 (file)
@@ -18,7 +18,6 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verifyZeroInteractions;
 
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
@@ -28,13 +27,13 @@ import io.netty.channel.ChannelPromise;
 import io.netty.channel.EventLoop;
 import io.netty.handler.codec.ByteToMessageDecoder;
 import io.netty.handler.codec.MessageToByteEncoder;
-import io.netty.util.concurrent.GenericFutureListener;
 import java.util.Collections;
 import java.util.Optional;
 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.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSessionListener;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
@@ -42,6 +41,7 @@ import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
 import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters;
 import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class AbstractNetconfSessionTest {
 
     @Mock
@@ -59,20 +59,15 @@ public class AbstractNetconfSessionTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
         doNothing().when(listener).onMessage(any(TestingNetconfSession.class), any(NetconfMessage.class));
         doNothing().when(listener).onSessionUp(any(TestingNetconfSession.class));
         doNothing().when(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
         doNothing().when(listener).onSessionTerminated(any(TestingNetconfSession.class),
                 any(NetconfTerminationReason.class));
 
-        doReturn(writeFuture).when(writeFuture).addListener(any(GenericFutureListener.class));
-
         doReturn(writeFuture).when(channel).newPromise();
-        doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class));
         doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class), any(ChannelPromise.class));
         doReturn(pipeline).when(channel).pipeline();
-        doReturn("mockChannel").when(channel).toString();
         doReturn(mock(ChannelFuture.class)).when(channel).close();
 
         doReturn(null).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
@@ -114,7 +109,6 @@ public class AbstractNetconfSessionTest {
     public void testReplaceHandlers() throws Exception {
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, 1L);
         final ChannelHandler mock = mock(ChannelHandler.class);
-        doReturn("handler").when(mock).toString();
 
         testingNetconfSession.replaceMessageDecoder(mock);
         verify(pipeline).replace(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER,
@@ -143,7 +137,7 @@ public class AbstractNetconfSessionTest {
     public void testEndOfInput() throws Exception {
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, 1L);
         testingNetconfSession.endOfInput();
-        verifyZeroInteractions(listener);
+        verifyNoMoreInteractions(listener);
         testingNetconfSession.sessionUp();
         testingNetconfSession.endOfInput();
         verify(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
@@ -157,5 +151,4 @@ public class AbstractNetconfSessionTest {
         testingNetconfSession.sendMessage(hello);
         verify(channel).writeAndFlush(hello, writeFuture);
     }
-
 }
index 899208a6702c2bb7b55f96affa5e3e6eae9fe260..fc91b5fc0e245d4e61186c7e70da5a9e2133aa87 100644 (file)
@@ -5,12 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.nettyutil.handler;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
index 1244991e32f89e15b4b5f9a4ed7cb4e1412ce216..948a9b680354190d9966c1c8040e7ab106f966ba 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.netconf.nettyutil.handler;
 
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Iterables;
index 3de88012ca3bb5566002a8f813296c13f194a6e9..60fe2d7a6bbc3b8fd9a1818ad2c2bac24b4dc481 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netconf.nettyutil.handler.ssh.client;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyObject;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
@@ -19,7 +18,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
 
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -143,7 +142,7 @@ public class AsyncSshHandlerTest {
         doReturn(channel).when(ctx).channel();
         doReturn(ctx).when(ctx).fireChannelActive();
         doReturn(ctx).when(ctx).fireChannelInactive();
-        doReturn(ctx).when(ctx).fireChannelRead(anyObject());
+        doReturn(ctx).when(ctx).fireChannelRead(any());
         doReturn(mock(ChannelFuture.class)).when(ctx).disconnect(any(ChannelPromise.class));
         doReturn(getMockedPromise()).when(ctx).newPromise();
     }
@@ -283,7 +282,7 @@ public class AsyncSshHandlerTest {
 
         doReturn(ioWriteFuture).when(asyncIn).writePacket(any(Buffer.class));
 
-        verifyZeroInteractions(firstWritePromise, secondWritePromise);
+        verifyNoMoreInteractions(firstWritePromise, secondWritePromise);
 
         // make first write stop pending
         firstWriteListener.operationComplete(ioWriteFuture);
index 6cf30edc891d3f5ffc220dca32f448f205b893ad..d2b3e17a47b76bf30fbd3d2ae9851678425b903a 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.netconf.util;
 
 import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 
 import java.util.Collections;
 import javax.xml.transform.dom.DOMResult;
@@ -47,12 +47,10 @@ public class NetconfUtilTest {
     public void testConflictingVersionDetection() throws Exception {
         final Document document = XmlUtil.readXmlToDocument(getClass()
                 .getResourceAsStream("/netconfMessages/conflictingversion/conflictingVersionResponse.xml"));
-        try {
-            NetconfUtil.checkIsMessageOk(document);
-            fail();
-        } catch (final IllegalStateException e) {
-            assertThat(e.getMessage(), containsString("Optimistic lock failed. Expected parent version 21, was 18"));
-        }
+
+        final IllegalStateException e = assertThrows(IllegalStateException.class,
+            () -> NetconfUtil.checkIsMessageOk(document));
+        assertThat(e.getMessage(), containsString("Optimistic lock failed. Expected parent version 21, was 18"));
     }
 
     @Test
index 7a8846db832f2de9ce88cc9fcb710d36734662e5..a8c233ecff66de0f155e47a9c8a4df5912ea7453 100644 (file)
@@ -8,12 +8,14 @@
 package org.opendaylight.netconf.sal.connect.netconf;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collections;
 import java.util.Map;
-import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
@@ -36,26 +38,25 @@ public class LibraryModulesSchemasTest {
         verifySchemas(libraryModulesSchemas);
     }
 
-
     private static void verifySchemas(final LibraryModulesSchemas libraryModulesSchemas) throws MalformedURLException {
         final Map<SourceIdentifier, URL> resolvedModulesSchema = libraryModulesSchemas.getAvailableModels();
-        Assert.assertThat(resolvedModulesSchema.size(), is(3));
+        assertThat(resolvedModulesSchema.size(), is(3));
 
-        Assert.assertTrue(resolvedModulesSchema.containsKey(RevisionSourceIdentifier.create("module-with-revision",
+        assertTrue(resolvedModulesSchema.containsKey(RevisionSourceIdentifier.create("module-with-revision",
                 Revision.of("2014-04-08"))));
-        Assert.assertThat(resolvedModulesSchema.get(
+        assertThat(resolvedModulesSchema.get(
                 RevisionSourceIdentifier.create("module-with-revision", Revision.of("2014-04-08"))),
                 is(new URL("http://localhost:8181/yanglib/schemas/module-with-revision/2014-04-08")));
 
-        Assert.assertTrue(resolvedModulesSchema.containsKey(
+        assertTrue(resolvedModulesSchema.containsKey(
                 RevisionSourceIdentifier.create("another-module-with-revision", Revision.of("2013-10-21"))));
-        Assert.assertThat(resolvedModulesSchema.get(
+        assertThat(resolvedModulesSchema.get(
                 RevisionSourceIdentifier.create("another-module-with-revision", Revision.of("2013-10-21"))),
                 is(new URL("http://localhost:8181/yanglib/schemas/another-module-with-revision/2013-10-21")));
 
-        Assert.assertTrue(resolvedModulesSchema.containsKey(
+        assertTrue(resolvedModulesSchema.containsKey(
                 RevisionSourceIdentifier.create("module-without-revision")));
-        Assert.assertThat(resolvedModulesSchema.get(
+        assertThat(resolvedModulesSchema.get(
                 RevisionSourceIdentifier.create("module-without-revision")),
                 is(new URL("http://localhost:8181/yanglib/schemas/module-without-revision/")));
     }
@@ -66,23 +67,20 @@ public class LibraryModulesSchemasTest {
                 LibraryModulesSchemas.create(getClass().getResource("/yang-library-fail.xml").toString());
 
         final Map<SourceIdentifier, URL> resolvedModulesSchema = libraryModulesSchemas.getAvailableModels();
-        Assert.assertThat(resolvedModulesSchema.size(), is(1));
+        assertThat(resolvedModulesSchema.size(), is(1));
 
-        Assert.assertFalse(resolvedModulesSchema.containsKey(
-                RevisionSourceIdentifier.create("module-with-bad-url")));
+        assertFalse(resolvedModulesSchema.containsKey(RevisionSourceIdentifier.create("module-with-bad-url")));
         //See BUG 8071 https://bugs.opendaylight.org/show_bug.cgi?id=8071
-        //Assert.assertFalse(resolvedModulesSchema.containsKey(
+        //assertFalse(resolvedModulesSchema.containsKey(
         //        RevisionSourceIdentifier.create("module-with-bad-revision", "bad-revision")));
-        Assert.assertTrue(resolvedModulesSchema.containsKey(
-                RevisionSourceIdentifier.create("good-ol-module")));
+        assertTrue(resolvedModulesSchema.containsKey(RevisionSourceIdentifier.create("good-ol-module")));
     }
 
-
     @Test
     public void testCreateFromInvalidAll() throws Exception {
         // test bad yang lib url
         LibraryModulesSchemas libraryModulesSchemas = LibraryModulesSchemas.create("ObviouslyBadUrl");
-        Assert.assertThat(libraryModulesSchemas.getAvailableModels(), is(Collections.emptyMap()));
+        assertThat(libraryModulesSchemas.getAvailableModels(), is(Collections.emptyMap()));
 
         // TODO test also fail on json and xml parsing. But can we fail not on runtime exceptions?
     }
index 2df5ed0765179d40b24cffaca76d669af85e14d5..24e7aa5fdab23581c476c2d3280e18dc71bdc5b8 100644 (file)
@@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyCollectionOf;
+import static org.mockito.ArgumentMatchers.anyCollection;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.after;
@@ -19,6 +19,7 @@ import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -44,7 +45,6 @@ import java.util.Set;
 import java.util.concurrent.Executors;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
@@ -84,19 +84,13 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.xml.sax.SAXException;
 
-@SuppressWarnings("checkstyle:IllegalCatch")
 public class NetconfDeviceTest extends AbstractTestModelTest {
 
     private static final NetconfMessage NOTIFICATION;
 
-    private static final ContainerNode COMPOSITE_NODE;
+    private static final ContainerNode COMPOSITE_NODE = mockClass(ContainerNode.class);
 
     static {
-        try {
-            COMPOSITE_NODE = mockClass(ContainerNode.class);
-        } catch (final Exception e) {
-            throw new RuntimeException(e);
-        }
         try {
             NOTIFICATION = new NetconfMessage(XmlUtil
                     .readXmlToDocument(NetconfDeviceTest.class.getResourceAsStream("/notification-payload.xml")));
@@ -140,7 +134,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
             } else {
                 return Futures.immediateFuture(SCHEMA_CONTEXT);
             }
-        }).when(schemaFactory).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
+        }).when(schemaFactory).createEffectiveModelContext(anyCollection());
 
         final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id,
                 schemaContext) -> {
@@ -168,9 +162,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(any(MountPointContext.class),
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class),
             any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
-        Mockito.verify(schemaFactory, times(2)).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
+        verify(schemaFactory, times(2)).createEffectiveModelContext(anyCollection());
     }
 
     @Test
@@ -188,7 +182,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 = new SchemaResolutionException("fail first",
                 Collections.emptyList(), HashMultimap.create());
         doReturn(Futures.immediateFailedFuture(schemaResolutionException))
-                .when(schemaFactory).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
+                .when(schemaFactory).createEffectiveModelContext(anyCollection());
 
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
                 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, STATE_SCHEMAS_RESOLVER);
@@ -205,9 +199,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        Mockito.verify(facade, Mockito.timeout(5000)).onDeviceDisconnected();
-        Mockito.verify(listener, Mockito.timeout(5000)).close();
-        Mockito.verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
+        verify(facade, timeout(5000)).onDeviceDisconnected();
+        verify(listener, timeout(5000)).close();
+        verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
     }
 
     @Test
@@ -229,7 +223,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
             } else {
                 return Futures.immediateFuture(SCHEMA_CONTEXT);
             }
-        }).when(schemaFactory).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
+        }).when(schemaFactory).createEffectiveModelContext(anyCollection());
 
         final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id,
             schemaContext) -> {
@@ -257,9 +251,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(any(MountPointContext.class),
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class),
             any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
-        Mockito.verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
+        verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
     }
 
     private static SchemaSourceRegistry getSchemaRegistry() {
@@ -400,7 +394,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setSalFacade(facade)
                 .setBaseSchemas(BASE_SCHEMAS)
                 .build();
-        final NetconfDevice netconfSpy = Mockito.spy(device);
+        final NetconfDevice netconfSpy = spy(device);
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
@@ -438,7 +432,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setSalFacade(facade)
                 .setBaseSchemas(BASE_SCHEMAS)
                 .build();
-        final NetconfDevice netconfSpy = Mockito.spy(device);
+        final NetconfDevice netconfSpy = spy(device);
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(false,
                 Lists.newArrayList(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0));
@@ -479,7 +473,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setSalFacade(facade)
                 .setBaseSchemas(BASE_SCHEMAS)
                 .build();
-        final NetconfDevice netconfSpy = Mockito.spy(device);
+        final NetconfDevice netconfSpy = spy(device);
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(false,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
@@ -517,7 +511,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setSalFacade(facade)
                 .setBaseSchemas(BASE_SCHEMAS)
                 .build();
-        final NetconfDevice netconfSpy = Mockito.spy(device);
+        final NetconfDevice netconfSpy = spy(device);
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(false, Collections.emptyList());
 
@@ -577,7 +571,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
     private static <T> T mockClass(final Class<T> remoteDeviceHandlerClass) {
         final T mock = mock(remoteDeviceHandlerClass);
-        Mockito.doReturn(remoteDeviceHandlerClass.getSimpleName()).when(mock).toString();
+        doReturn(remoteDeviceHandlerClass.getSimpleName()).when(mock).toString();
         return mock;
     }
 
index a8491df28498cd98af2c00c01b4410969e99b215..50055813fee8570c18689827fc28ef16c0df3115 100644 (file)
@@ -5,13 +5,12 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.sal.connect.netconf.listener;
 
 import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Lists;
index 155c1c60e0476f03e0737cd029f538a7c1aa41a5..0c13249f5323d961f82c0e1430b7585b50bc1653 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
 
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME;
index 0320a6e2c04327aca0afd21748502caad5dbd617..83f1912cc00cd9ea2b4137170b97b1c48b970068 100644 (file)
@@ -13,7 +13,6 @@ import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import com.google.common.util.concurrent.FluentFuture;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
@@ -73,23 +72,23 @@ public class NetconfBaseOpsTest extends AbstractTestModelTest {
         final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
         final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(data).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(data).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(data).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(data).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(ok).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(ok).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(ok).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(ok).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(ok).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(ok).buildFuture());
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME)))
-                .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
+                .thenReturn(RpcResultBuilder.success(ok).buildFuture());
         final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(
             new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
         final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);