Modernize collection allocation
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / NetconfNodeActorTest.java
index 5abb6ce320a87034961515730249c803a8321c80..4f79e46c1a9468a8ae5d2f9c7eda8cc09a8640f7 100644 (file)
@@ -5,16 +5,15 @@
  * 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.topology.singleton.impl;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.after;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
@@ -45,6 +44,7 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.SettableFuture;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Scanner;
@@ -56,20 +56,19 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatcher;
 import org.mockito.Mock;
 import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMRpcException;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.impl.actors.NetconfNodeActor;
 import org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException;
@@ -83,6 +82,7 @@ import org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterAc
 import org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint;
 import org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -189,7 +189,7 @@ public class NetconfNodeActorTest {
 
     @After
     public void teardown() {
-        TestKit.shutdownActorSystem(system, Boolean.TRUE);
+        TestKit.shutdownActorSystem(system, true);
         system = null;
     }
 
@@ -198,7 +198,7 @@ public class NetconfNodeActorTest {
 
         // Test CreateInitialMasterActorData.
 
-        initializeMaster(Lists.newArrayList());
+        initializeMaster(new ArrayList<>());
 
         // Test RefreshSetupMasterActorData.
 
@@ -444,7 +444,7 @@ public class NetconfNodeActorTest {
 
         // RPC with no response output.
 
-        doReturn(Futures.immediateCheckedFuture(null)).when(mockDOMRpcService).invokeRpc(any(), any());
+        doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMRpcService).invokeRpc(any(), any());
 
         DOMRpcResult result = slaveDomRPCService.invokeRpc(schemaPath, outputNode).get(2, TimeUnit.SECONDS);
 
@@ -452,7 +452,7 @@ public class NetconfNodeActorTest {
 
         // RPC with response output.
 
-        doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(outputNode)))
+        doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode)))
                 .when(mockDOMRpcService).invokeRpc(any(), any());
 
         result = slaveDomRPCService.invokeRpc(schemaPath, outputNode).get(2, TimeUnit.SECONDS);
@@ -462,7 +462,7 @@ public class NetconfNodeActorTest {
 
         // RPC with response error.
 
-        doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(rpcError)))
+        doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(rpcError)))
                 .when(mockDOMRpcService).invokeRpc(any(), any());
 
         result = slaveDomRPCService.invokeRpc(schemaPath, outputNode).get(2, TimeUnit.SECONDS);
@@ -472,7 +472,7 @@ public class NetconfNodeActorTest {
 
         // RPC with response output and error.
 
-        doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(outputNode, rpcError)))
+        doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode, rpcError)))
                 .when(mockDOMRpcService).invokeRpc(any(), any());
 
         final DOMRpcResult resultOutputError =
@@ -485,7 +485,7 @@ public class NetconfNodeActorTest {
 
         exception.expect(DOMRpcException.class);
 
-        doReturn(Futures.immediateFailedCheckedFuture(new ClusteringRpcException("mock")))
+        doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock")))
                 .when(mockDOMRpcService).invokeRpc(any(), any());
 
         try {
@@ -498,9 +498,9 @@ public class NetconfNodeActorTest {
     @Test
     public void testSlaveNewTransactionRequests() {
 
-        doReturn(mock(DOMDataReadOnlyTransaction.class)).when(mockDOMDataBroker).newReadOnlyTransaction();
-        doReturn(mock(DOMDataReadWriteTransaction.class)).when(mockDOMDataBroker).newReadWriteTransaction();
-        doReturn(mock(DOMDataWriteTransaction.class)).when(mockDOMDataBroker).newWriteOnlyTransaction();
+        doReturn(mock(DOMDataTreeReadTransaction.class)).when(mockDOMDataBroker).newReadOnlyTransaction();
+        doReturn(mock(DOMDataTreeReadWriteTransaction.class)).when(mockDOMDataBroker).newReadWriteTransaction();
+        doReturn(mock(DOMDataTreeWriteTransaction.class)).when(mockDOMDataBroker).newWriteOnlyTransaction();
 
         initializeMaster(Collections.emptyList());
         registerSlaveMountPoint();
@@ -543,7 +543,7 @@ public class NetconfNodeActorTest {
         return slaveRef;
     }
 
-    private void initializeMaster(List<SourceIdentifier> sourceIdentifiers) {
+    private void initializeMaster(final List<SourceIdentifier> sourceIdentifiers) {
         masterRef.tell(new CreateInitialMasterActorData(mockDOMDataBroker, sourceIdentifiers,
                 mockDOMRpcService), testKit.getRef());
 
@@ -560,17 +560,11 @@ public class NetconfNodeActorTest {
         doReturn(mockMountPointReg).when(mockMountPointBuilder).register();
     }
 
-    private PotentialSchemaSource<?> withSourceId(final SourceIdentifier identifier) {
-        return argThat(new ArgumentMatcher<PotentialSchemaSource<?>>() {
-            @Override
-            public boolean matches(final Object argument) {
-                final PotentialSchemaSource<?> potentialSchemaSource = (PotentialSchemaSource<?>) argument;
-                return identifier.equals(potentialSchemaSource.getSourceIdentifier());
-            }
-        });
+    private static PotentialSchemaSource<?> withSourceId(final SourceIdentifier identifier) {
+        return argThat(argument -> identifier.equals(argument.getSourceIdentifier()));
     }
 
-    private String convertStreamToString(final InputStream is) {
+    private static String convertStreamToString(final InputStream is) {
         try (Scanner scanner = new Scanner(is)) {
             return scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
         }