Simplify invocation mocking 75/110275/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Feb 2024 13:17:20 +0000 (14:17 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Feb 2024 13:19:11 +0000 (14:19 +0100)
Use Invocation.getArgument() instead of getArguments() and casting.
While we are here, fix minor warnings around ArgumentCaptor by using
local variable type inference.

Change-Id: I75756f79a9e0820d61acea847c8e635cf5657f36
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceTest.java

index ea53d20655f6a3a3f7114779cbf07467d1d9b67b..25e1628293f37bb3dc2b414d05c3cf139f020884 100644 (file)
@@ -103,7 +103,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final SchemaResolutionException schemaResolutionException =
                 new SchemaResolutionException("fail first", TEST_SID, new Throwable("YangTools parser fail"));
         doAnswer(invocation -> {
-            if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
+            if (invocation.getArgument(0, Collection.class).size() == 2) {
                 return Futures.immediateFailedFuture(schemaResolutionException);
             } else {
                 return Futures.immediateFuture(SCHEMA_CONTEXT);
@@ -399,7 +399,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
         netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
 
-        final ArgumentCaptor<NetconfDeviceSchema> argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class);
+        final var argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class);
         verify(facade, timeout(5000)).onDeviceConnected(argument.capture(), any(NetconfSessionPreferences.class),
             any(RemoteDeviceServices.class));
         argument.getValue().capabilities().resolvedCapabilities()
@@ -429,7 +429,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
         netconfSpy.onRemoteSessionUp(sessionCaps, listener);
 
-        final ArgumentCaptor<NetconfDeviceSchema> argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class);
+        final var argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class);
         verify(facade, timeout(5000)).onDeviceConnected(argument.capture(), any(NetconfSessionPreferences.class),
                 any(RemoteDeviceServices.class));
 
@@ -468,7 +468,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
         netconfSpy.onRemoteSessionUp(sessionCaps, listener);
 
-        final ArgumentCaptor<NetconfDeviceSchema> argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class);
+        final var argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class);
         verify(facade, timeout(5000)).onDeviceConnected(argument.capture(), any(NetconfSessionPreferences.class),
                 any(RemoteDeviceServices.class));
         final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().capabilities();