From 6cc971daab8c73083c34f7861243e286c6dc3210 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Mon, 10 Mar 2025 02:16:21 +0100 Subject: [PATCH] packages/modules/Connectivity: remove usages of deprecated Mockito matchers Test: m checkbuild Flag: TEST_ONLY Bug: 310268946 Change-Id: Icef421511b6fed6dc7912a9b703773ba5700c62a --- .../unit/src/android/net/ip/IpServerTest.java | 6 ++--- .../tethering/BpfCoordinatorTest.java | 12 +++++----- .../tethering/EntitlementManagerTest.java | 10 ++++----- .../tethering/OffloadControllerTest.java | 13 +++++------ .../tethering/TetheringConfigurationTest.java | 2 +- .../networkstack/tethering/TetheringTest.java | 6 ++--- .../RemoteAuthConnectionCacheTest.java | 8 +++---- .../remoteauth/RemoteAuthPlatformTest.java | 4 ++-- .../module/util/ip/ConntrackMonitorTest.java | 2 +- .../java/android/net/IpSecManagerTest.java | 22 +++++++++---------- .../server/ConnectivityServiceTest.java | 2 +- .../server/IpSecServiceParameterizedTest.java | 3 --- .../IpSecServiceRefcountedResourceTest.java | 14 ++++++------ .../com/android/server/IpSecServiceTest.java | 8 +++---- .../server/net/NetworkStatsObserversTest.java | 4 ++-- .../server/net/NetworkStatsServiceTest.java | 2 +- 16 files changed, 57 insertions(+), 61 deletions(-) diff --git a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java index 84b301fc0a..280d2c5368 100644 --- a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java +++ b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java @@ -47,9 +47,9 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java index dd10cc3414..b537fb65a3 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java @@ -71,12 +71,12 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.argThat; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.inOrder; diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/EntitlementManagerTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/EntitlementManagerTest.java index 58e18940e4..7bfdb22cfc 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/EntitlementManagerTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/EntitlementManagerTest.java @@ -45,11 +45,11 @@ import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.never; diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/OffloadControllerTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/OffloadControllerTest.java index 36c15a7ca1..ce5686098e 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/OffloadControllerTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/OffloadControllerTest.java @@ -42,11 +42,10 @@ import static junit.framework.Assert.assertNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.never; @@ -282,7 +281,7 @@ public class OffloadControllerTest { // This LinkProperties value does not differ from the default upstream. // There should be no extraneous call to setUpstreamParameters(). inOrder.verify(mHardware, never()).setUpstreamParameters( - anyObject(), anyObject(), anyObject(), anyObject()); + any(), any(), any(), any()); inOrder.verifyNoMoreInteractions(); final LinkProperties lp = new LinkProperties(); @@ -410,7 +409,7 @@ public class OffloadControllerTest { // This LinkProperties value does not differ from the default upstream. // There should be no extraneous call to setUpstreamParameters(). inOrder.verify(mHardware, never()).setUpstreamParameters( - anyObject(), anyObject(), anyObject(), anyObject()); + any(), any(), any(), any()); inOrder.verifyNoMoreInteractions(); } diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java index 0159573acf..999e0dbf4c 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java @@ -37,7 +37,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java index 51efaf8746..031b6520f3 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java @@ -96,9 +96,9 @@ import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.notNull; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; diff --git a/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthConnectionCacheTest.java b/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthConnectionCacheTest.java index 00f35d3a13..2e39431daf 100644 --- a/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthConnectionCacheTest.java +++ b/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthConnectionCacheTest.java @@ -19,7 +19,7 @@ package com.android.server.remoteauth; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -98,7 +98,7 @@ public class RemoteAuthConnectionCacheTest { @Test public void testGetConnection_failedToConnect() { mConnectionCache.setConnectionInfo(mConnectionInfo); - doReturn(null).when(mConnectivityManager).connect(eq(mConnectionInfo), anyObject()); + doReturn(null).when(mConnectivityManager).connect(eq(mConnectionInfo), any()); assertNull(mConnectionCache.getConnection(CONNECTION_ID)); } @@ -108,7 +108,7 @@ public class RemoteAuthConnectionCacheTest { mConnectionCache.setConnectionInfo(mConnectionInfo); doThrow(ConnectionException.class) .when(mConnectivityManager) - .connect(eq(mConnectionInfo), anyObject()); + .connect(eq(mConnectionInfo), any()); assertNull(mConnectionCache.getConnection(CONNECTION_ID)); } @@ -116,7 +116,7 @@ public class RemoteAuthConnectionCacheTest { @Test public void testGetConnection_connectionSucceed() { mConnectionCache.setConnectionInfo(mConnectionInfo); - doReturn(mConnection).when(mConnectivityManager).connect(eq(mConnectionInfo), anyObject()); + doReturn(mConnection).when(mConnectivityManager).connect(eq(mConnectionInfo), any()); assertEquals(mConnection, mConnectionCache.getConnection(CONNECTION_ID)); } diff --git a/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthPlatformTest.java b/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthPlatformTest.java index 8975d52b85..cce6b5e192 100644 --- a/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthPlatformTest.java +++ b/remoteauth/tests/unit/src/com/android/server/remoteauth/RemoteAuthPlatformTest.java @@ -19,7 +19,7 @@ package com.android.server.remoteauth; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; @@ -82,6 +82,6 @@ public class RemoteAuthPlatformTest { @Override public void onFailure(int errorCode) {} })); - verify(mConnection, times(1)).sendRequest(eq(REQUEST), anyObject()); + verify(mConnection, times(1)).sendRequest(eq(REQUEST), any()); } } diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/ip/ConntrackMonitorTest.java b/staticlibs/tests/unit/src/com/android/net/module/util/ip/ConntrackMonitorTest.java index 7ee376c98d..90476a79d3 100644 --- a/staticlibs/tests/unit/src/com/android/net/module/util/ip/ConntrackMonitorTest.java +++ b/staticlibs/tests/unit/src/com/android/net/module/util/ip/ConntrackMonitorTest.java @@ -29,7 +29,7 @@ import static com.android.net.module.util.netlink.NetlinkConstants.IPCTNL_MSG_CT import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; diff --git a/tests/unit/java/android/net/IpSecManagerTest.java b/tests/unit/java/android/net/IpSecManagerTest.java index 335f53969d..d07dea07b2 100644 --- a/tests/unit/java/android/net/IpSecManagerTest.java +++ b/tests/unit/java/android/net/IpSecManagerTest.java @@ -23,10 +23,10 @@ import static android.system.OsConstants.SOCK_DGRAM; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -100,7 +100,7 @@ public class IpSecManagerTest { when(mMockIpSecService.allocateSecurityParameterIndex( eq(GOOGLE_DNS_4.getHostAddress()), eq(DROID_SPI), - anyObject())) + any())) .thenReturn(spiResp); IpSecManager.SecurityParameterIndex droidSpi = @@ -119,7 +119,7 @@ public class IpSecManagerTest { when(mMockIpSecService.allocateSecurityParameterIndex( eq(GOOGLE_DNS_4.getHostAddress()), eq(IpSecManager.INVALID_SECURITY_PARAMETER_INDEX), - anyObject())) + any())) .thenReturn(spiResp); IpSecManager.SecurityParameterIndex randomSpi = @@ -140,7 +140,7 @@ public class IpSecManagerTest { IpSecSpiResponse spiResp = new IpSecSpiResponse(IpSecManager.Status.RESOURCE_UNAVAILABLE, 0, 0); when(mMockIpSecService.allocateSecurityParameterIndex( - anyString(), anyInt(), anyObject())) + anyString(), anyInt(), any())) .thenReturn(spiResp); try { @@ -157,7 +157,7 @@ public class IpSecManagerTest { public void testAllocSpiSpiUnavailableException() throws Exception { IpSecSpiResponse spiResp = new IpSecSpiResponse(IpSecManager.Status.SPI_UNAVAILABLE, 0, 0); when(mMockIpSecService.allocateSecurityParameterIndex( - anyString(), anyInt(), anyObject())) + anyString(), anyInt(), any())) .thenReturn(spiResp); try { @@ -187,7 +187,7 @@ public class IpSecManagerTest { DUMMY_RESOURCE_ID, TEST_UDP_ENCAP_PORT, Os.socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)); - when(mMockIpSecService.openUdpEncapsulationSocket(eq(TEST_UDP_ENCAP_PORT), anyObject())) + when(mMockIpSecService.openUdpEncapsulationSocket(eq(TEST_UDP_ENCAP_PORT), any())) .thenReturn(udpEncapResp); IpSecManager.UdpEncapsulationSocket encapSocket = @@ -236,7 +236,7 @@ public class IpSecManagerTest { TEST_UDP_ENCAP_PORT, Os.socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)); - when(mMockIpSecService.openUdpEncapsulationSocket(eq(0), anyObject())) + when(mMockIpSecService.openUdpEncapsulationSocket(eq(0), any())) .thenReturn(udpEncapResp); IpSecManager.UdpEncapsulationSocket encapSocket = @@ -267,7 +267,7 @@ public class IpSecManagerTest { new IpSecTunnelInterfaceResponse(IpSecManager.Status.OK, resourceId, intfName); when(mMockIpSecService.createTunnelInterface( eq(VTI_LOCAL_ADDRESS.getHostAddress()), eq(GOOGLE_DNS_4.getHostAddress()), - anyObject(), anyObject(), anyString())) + any(), any(), anyString())) .thenReturn(dummyResponse); IpSecManager.IpSecTunnelInterface tunnelIntf = mIpSecManager.createIpSecTunnelInterface( diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index 19a41d88e9..9f52320596 100755 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -220,7 +220,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; diff --git a/tests/unit/java/com/android/server/IpSecServiceParameterizedTest.java b/tests/unit/java/com/android/server/IpSecServiceParameterizedTest.java index 8037542ae4..65beda13e0 100644 --- a/tests/unit/java/com/android/server/IpSecServiceParameterizedTest.java +++ b/tests/unit/java/com/android/server/IpSecServiceParameterizedTest.java @@ -37,9 +37,6 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/tests/unit/java/com/android/server/IpSecServiceRefcountedResourceTest.java b/tests/unit/java/com/android/server/IpSecServiceRefcountedResourceTest.java index 8595ab90da..0e216d7115 100644 --- a/tests/unit/java/com/android/server/IpSecServiceRefcountedResourceTest.java +++ b/tests/unit/java/com/android/server/IpSecServiceRefcountedResourceTest.java @@ -19,9 +19,9 @@ package com.android.server; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -111,7 +111,7 @@ public class IpSecServiceRefcountedResourceTest { assertResourceState(resource, 1, 0, 0, 0, 0); // Verify linking to binder death - verify(binderMock).linkToDeath(anyObject(), anyInt()); + verify(binderMock).linkToDeath(any(), anyInt()); } @Test @@ -129,14 +129,14 @@ public class IpSecServiceRefcountedResourceTest { assertResourceState(childResource, 2, 0, 0, 0, 0); // Verify linking to binder death - verify(binderMockChild).linkToDeath(anyObject(), anyInt()); - verify(binderMockParent).linkToDeath(anyObject(), anyInt()); + verify(binderMockChild).linkToDeath(any(), anyInt()); + verify(binderMockParent).linkToDeath(any(), anyInt()); } @Test public void testFailLinkToDeath() throws RemoteException { IBinder binderMock = mock(IBinder.class); - doThrow(new RemoteException()).when(binderMock).linkToDeath(anyObject(), anyInt()); + doThrow(new RemoteException()).when(binderMock).linkToDeath(any(), anyInt()); try { getTestRefcountedResource(binderMock); diff --git a/tests/unit/java/com/android/server/IpSecServiceTest.java b/tests/unit/java/com/android/server/IpSecServiceTest.java index 4b6857c308..32c61fb9f8 100644 --- a/tests/unit/java/com/android/server/IpSecServiceTest.java +++ b/tests/unit/java/com/android/server/IpSecServiceTest.java @@ -26,10 +26,10 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/tests/unit/java/com/android/server/net/NetworkStatsObserversTest.java b/tests/unit/java/com/android/server/net/NetworkStatsObserversTest.java index e62ac74429..d807397714 100644 --- a/tests/unit/java/com/android/server/net/NetworkStatsObserversTest.java +++ b/tests/unit/java/com/android/server/net/NetworkStatsObserversTest.java @@ -35,8 +35,8 @@ import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import android.content.Context; import android.net.DataUsageRequest; diff --git a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java index 697bf9e845..869c02745d 100644 --- a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java +++ b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java @@ -93,7 +93,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock;