Merge "Factorize custom asserts." am: 6c176efa3d
am: 99fbb40990
Change-Id: I65ea7497abb8b77ebd10ba622075ef3b6c49b2a8
diff --git a/core/java/android/net/IpSecConfig.java b/core/java/android/net/IpSecConfig.java
index a64014f..575c5ed 100644
--- a/core/java/android/net/IpSecConfig.java
+++ b/core/java/android/net/IpSecConfig.java
@@ -15,6 +15,7 @@
*/
package android.net;
+import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
@@ -333,25 +334,25 @@
}
};
- @VisibleForTesting
- /** Equals method used for testing */
- public static boolean equals(IpSecConfig lhs, IpSecConfig rhs) {
- if (lhs == null || rhs == null) return (lhs == rhs);
- return (lhs.mMode == rhs.mMode
- && lhs.mSourceAddress.equals(rhs.mSourceAddress)
- && lhs.mDestinationAddress.equals(rhs.mDestinationAddress)
- && ((lhs.mNetwork != null && lhs.mNetwork.equals(rhs.mNetwork))
- || (lhs.mNetwork == rhs.mNetwork))
- && lhs.mEncapType == rhs.mEncapType
- && lhs.mEncapSocketResourceId == rhs.mEncapSocketResourceId
- && lhs.mEncapRemotePort == rhs.mEncapRemotePort
- && lhs.mNattKeepaliveInterval == rhs.mNattKeepaliveInterval
- && lhs.mSpiResourceId == rhs.mSpiResourceId
- && IpSecAlgorithm.equals(lhs.mEncryption, rhs.mEncryption)
- && IpSecAlgorithm.equals(lhs.mAuthenticatedEncryption, rhs.mAuthenticatedEncryption)
- && IpSecAlgorithm.equals(lhs.mAuthentication, rhs.mAuthentication)
- && lhs.mMarkValue == rhs.mMarkValue
- && lhs.mMarkMask == rhs.mMarkMask
- && lhs.mXfrmInterfaceId == rhs.mXfrmInterfaceId);
+ @Override
+ public boolean equals(@Nullable Object other) {
+ if (!(other instanceof IpSecConfig)) return false;
+ final IpSecConfig rhs = (IpSecConfig) other;
+ return (mMode == rhs.mMode
+ && mSourceAddress.equals(rhs.mSourceAddress)
+ && mDestinationAddress.equals(rhs.mDestinationAddress)
+ && ((mNetwork != null && mNetwork.equals(rhs.mNetwork))
+ || (mNetwork == rhs.mNetwork))
+ && mEncapType == rhs.mEncapType
+ && mEncapSocketResourceId == rhs.mEncapSocketResourceId
+ && mEncapRemotePort == rhs.mEncapRemotePort
+ && mNattKeepaliveInterval == rhs.mNattKeepaliveInterval
+ && mSpiResourceId == rhs.mSpiResourceId
+ && IpSecAlgorithm.equals(mEncryption, rhs.mEncryption)
+ && IpSecAlgorithm.equals(mAuthenticatedEncryption, rhs.mAuthenticatedEncryption)
+ && IpSecAlgorithm.equals(mAuthentication, rhs.mAuthentication)
+ && mMarkValue == rhs.mMarkValue
+ && mMarkMask == rhs.mMarkMask
+ && mXfrmInterfaceId == rhs.mXfrmInterfaceId);
}
}
diff --git a/core/java/android/net/IpSecTransform.java b/core/java/android/net/IpSecTransform.java
index 36111f2..44a0a4f 100644
--- a/core/java/android/net/IpSecTransform.java
+++ b/core/java/android/net/IpSecTransform.java
@@ -151,15 +151,13 @@
}
/**
- * Equals method used for testing
- *
- * @hide
+ * Standard equals.
*/
- @VisibleForTesting
- public static boolean equals(IpSecTransform lhs, IpSecTransform rhs) {
- if (lhs == null || rhs == null) return (lhs == rhs);
- return IpSecConfig.equals(lhs.getConfig(), rhs.getConfig())
- && lhs.mResourceId == rhs.mResourceId;
+ public boolean equals(Object other) {
+ if (this == other) return true;
+ if (!(other instanceof IpSecTransform)) return false;
+ final IpSecTransform rhs = (IpSecTransform) other;
+ return getConfig().equals(rhs.getConfig()) && mResourceId == rhs.mResourceId;
}
/**
diff --git a/tests/net/Android.bp b/tests/net/Android.bp
index eb25acf..135bf90 100644
--- a/tests/net/Android.bp
+++ b/tests/net/Android.bp
@@ -6,7 +6,6 @@
static_libs: [
"FrameworksNetCommonTests",
"frameworks-base-testutils",
- "frameworks-net-testutils",
"framework-protos",
"androidx.test.rules",
"mockito-target-minus-junit4",
diff --git a/tests/net/common/Android.bp b/tests/net/common/Android.bp
index db1ccb4..e44d460 100644
--- a/tests/net/common/Android.bp
+++ b/tests/net/common/Android.bp
@@ -21,12 +21,12 @@
srcs: ["java/**/*.java", "java/**/*.kt"],
static_libs: [
"androidx.test.rules",
- "frameworks-net-testutils",
"junit",
"mockito-target-minus-junit4",
+ "net-tests-utils",
"platform-test-annotations",
],
libs: [
"android.test.base.stubs",
],
-}
\ No newline at end of file
+}
diff --git a/tests/net/common/java/android/net/IpPrefixTest.java b/tests/net/common/java/android/net/IpPrefixTest.java
index 719960d..985e10d 100644
--- a/tests/net/common/java/android/net/IpPrefixTest.java
+++ b/tests/net/common/java/android/net/IpPrefixTest.java
@@ -16,16 +16,18 @@
package android.net;
+import static com.android.testutils.MiscAssertsKt.assertEqualBothWays;
+import static com.android.testutils.MiscAssertsKt.assertFieldCountEquals;
+import static com.android.testutils.MiscAssertsKt.assertNotEqualEitherWay;
+import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
+
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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 android.os.Parcel;
-
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -171,56 +173,46 @@
}
- private void assertAreEqual(Object o1, Object o2) {
- assertTrue(o1.equals(o2));
- assertTrue(o2.equals(o1));
- }
-
- private void assertAreNotEqual(Object o1, Object o2) {
- assertFalse(o1.equals(o2));
- assertFalse(o2.equals(o1));
- }
-
@Test
public void testEquals() {
IpPrefix p1, p2;
p1 = new IpPrefix("192.0.2.251/23");
p2 = new IpPrefix(new byte[]{(byte) 192, (byte) 0, (byte) 2, (byte) 251}, 23);
- assertAreEqual(p1, p2);
+ assertEqualBothWays(p1, p2);
p1 = new IpPrefix("192.0.2.5/23");
- assertAreEqual(p1, p2);
+ assertEqualBothWays(p1, p2);
p1 = new IpPrefix("192.0.2.5/24");
- assertAreNotEqual(p1, p2);
+ assertNotEqualEitherWay(p1, p2);
p1 = new IpPrefix("192.0.4.5/23");
- assertAreNotEqual(p1, p2);
+ assertNotEqualEitherWay(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::80/122");
p2 = new IpPrefix(IPV6_BYTES, 122);
assertEquals("2001:db8:dead:beef:f00::80/122", p2.toString());
- assertAreEqual(p1, p2);
+ assertEqualBothWays(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::bf/122");
- assertAreEqual(p1, p2);
+ assertEqualBothWays(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::8:0/123");
- assertAreNotEqual(p1, p2);
+ assertNotEqualEitherWay(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef::/122");
- assertAreNotEqual(p1, p2);
+ assertNotEqualEitherWay(p1, p2);
// 192.0.2.4/32 != c000:0204::/32.
byte[] ipv6bytes = new byte[16];
System.arraycopy(IPV4_BYTES, 0, ipv6bytes, 0, IPV4_BYTES.length);
p1 = new IpPrefix(ipv6bytes, 32);
- assertAreEqual(p1, new IpPrefix("c000:0204::/32"));
+ assertEqualBothWays(p1, new IpPrefix("c000:0204::/32"));
p2 = new IpPrefix(IPV4_BYTES, 32);
- assertAreNotEqual(p1, p2);
+ assertNotEqualEitherWay(p1, p2);
}
@Test
@@ -356,25 +348,6 @@
assertEquals(InetAddress.parseNumericAddress("192.0.2.0"), p.getAddress());
}
- public IpPrefix passThroughParcel(IpPrefix p) {
- Parcel parcel = Parcel.obtain();
- IpPrefix p2 = null;
- try {
- p.writeToParcel(parcel, 0);
- parcel.setDataPosition(0);
- p2 = IpPrefix.CREATOR.createFromParcel(parcel);
- } finally {
- parcel.recycle();
- }
- assertNotNull(p2);
- return p2;
- }
-
- public void assertParcelingIsLossless(IpPrefix p) {
- IpPrefix p2 = passThroughParcel(p);
- assertEquals(p, p2);
- }
-
@Test
public void testParceling() {
IpPrefix p;
@@ -386,5 +359,7 @@
p = new IpPrefix("192.0.2.0/25");
assertParcelingIsLossless(p);
assertTrue(p.isIPv4());
+
+ assertFieldCountEquals(2, IpPrefix.class);
}
}
diff --git a/tests/net/common/java/android/net/LinkAddressTest.java b/tests/net/common/java/android/net/LinkAddressTest.java
index d462441b..b2e573b 100644
--- a/tests/net/common/java/android/net/LinkAddressTest.java
+++ b/tests/net/common/java/android/net/LinkAddressTest.java
@@ -27,15 +27,17 @@
import static android.system.OsConstants.RT_SCOPE_SITE;
import static android.system.OsConstants.RT_SCOPE_UNIVERSE;
+import static com.android.testutils.MiscAssertsKt.assertEqualBothWays;
+import static com.android.testutils.MiscAssertsKt.assertNotEqualEitherWay;
+import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
+import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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 android.os.Parcel;
-
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -217,67 +219,56 @@
l1.isSameAddressAs(l2));
}
- private void assertLinkAddressesEqual(LinkAddress l1, LinkAddress l2) {
- assertTrue(l1 + " unexpectedly not equal to " + l2, l1.equals(l2));
- assertTrue(l2 + " unexpectedly not equal to " + l1, l2.equals(l1));
- assertEquals(l1.hashCode(), l2.hashCode());
- }
-
- private void assertLinkAddressesNotEqual(LinkAddress l1, LinkAddress l2) {
- assertFalse(l1 + " unexpectedly equal to " + l2, l1.equals(l2));
- assertFalse(l2 + " unexpectedly equal to " + l1, l2.equals(l1));
- }
-
@Test
public void testEqualsAndSameAddressAs() {
LinkAddress l1, l2, l3;
l1 = new LinkAddress("2001:db8::1/64");
l2 = new LinkAddress("2001:db8::1/64");
- assertLinkAddressesEqual(l1, l2);
+ assertEqualBothWays(l1, l2);
assertIsSameAddressAs(l1, l2);
l2 = new LinkAddress("2001:db8::1/65");
- assertLinkAddressesNotEqual(l1, l2);
+ assertNotEqualEitherWay(l1, l2);
assertIsNotSameAddressAs(l1, l2);
l2 = new LinkAddress("2001:db8::2/64");
- assertLinkAddressesNotEqual(l1, l2);
+ assertNotEqualEitherWay(l1, l2);
assertIsNotSameAddressAs(l1, l2);
l1 = new LinkAddress("192.0.2.1/24");
l2 = new LinkAddress("192.0.2.1/24");
- assertLinkAddressesEqual(l1, l2);
+ assertEqualBothWays(l1, l2);
assertIsSameAddressAs(l1, l2);
l2 = new LinkAddress("192.0.2.1/23");
- assertLinkAddressesNotEqual(l1, l2);
+ assertNotEqualEitherWay(l1, l2);
assertIsNotSameAddressAs(l1, l2);
l2 = new LinkAddress("192.0.2.2/24");
- assertLinkAddressesNotEqual(l1, l2);
+ assertNotEqualEitherWay(l1, l2);
assertIsNotSameAddressAs(l1, l2);
// Check equals() and isSameAddressAs() on identical addresses with different flags.
l1 = new LinkAddress(V6_ADDRESS, 64);
l2 = new LinkAddress(V6_ADDRESS, 64, 0, RT_SCOPE_UNIVERSE);
- assertLinkAddressesEqual(l1, l2);
+ assertEqualBothWays(l1, l2);
assertIsSameAddressAs(l1, l2);
l2 = new LinkAddress(V6_ADDRESS, 64, IFA_F_DEPRECATED, RT_SCOPE_UNIVERSE);
- assertLinkAddressesNotEqual(l1, l2);
+ assertNotEqualEitherWay(l1, l2);
assertIsSameAddressAs(l1, l2);
// Check equals() and isSameAddressAs() on identical addresses with different scope.
l1 = new LinkAddress(V4_ADDRESS, 24);
l2 = new LinkAddress(V4_ADDRESS, 24, 0, RT_SCOPE_UNIVERSE);
- assertLinkAddressesEqual(l1, l2);
+ assertEqualBothWays(l1, l2);
assertIsSameAddressAs(l1, l2);
l2 = new LinkAddress(V4_ADDRESS, 24, 0, RT_SCOPE_HOST);
- assertLinkAddressesNotEqual(l1, l2);
+ assertNotEqualEitherWay(l1, l2);
assertIsSameAddressAs(l1, l2);
// Addresses with the same start or end bytes aren't equal between families.
@@ -291,10 +282,10 @@
assertTrue(Arrays.equals(ipv4Bytes, l2FirstIPv6Bytes));
assertTrue(Arrays.equals(ipv4Bytes, l3LastIPv6Bytes));
- assertLinkAddressesNotEqual(l1, l2);
+ assertNotEqualEitherWay(l1, l2);
assertIsNotSameAddressAs(l1, l2);
- assertLinkAddressesNotEqual(l1, l3);
+ assertNotEqualEitherWay(l1, l3);
assertIsNotSameAddressAs(l1, l3);
// Because we use InetAddress, an IPv4 address is equal to its IPv4-mapped address.
@@ -302,7 +293,7 @@
String addressString = V4 + "/24";
l1 = new LinkAddress(addressString);
l2 = new LinkAddress("::ffff:" + addressString);
- assertLinkAddressesEqual(l1, l2);
+ assertEqualBothWays(l1, l2);
assertIsSameAddressAs(l1, l2);
}
@@ -319,25 +310,6 @@
assertNotEquals(l1.hashCode(), l2.hashCode());
}
- private LinkAddress passThroughParcel(LinkAddress l) {
- Parcel p = Parcel.obtain();
- LinkAddress l2 = null;
- try {
- l.writeToParcel(p, 0);
- p.setDataPosition(0);
- l2 = LinkAddress.CREATOR.createFromParcel(p);
- } finally {
- p.recycle();
- }
- assertNotNull(l2);
- return l2;
- }
-
- private void assertParcelingIsLossless(LinkAddress l) {
- LinkAddress l2 = passThroughParcel(l);
- assertEquals(l, l2);
- }
-
@Test
public void testParceling() {
LinkAddress l;
@@ -346,7 +318,7 @@
assertParcelingIsLossless(l);
l = new LinkAddress(V4 + "/28", IFA_F_PERMANENT, RT_SCOPE_LINK);
- assertParcelingIsLossless(l);
+ assertParcelSane(l, 4);
}
private void assertGlobalPreferred(LinkAddress l, String msg) {
diff --git a/tests/net/common/java/android/net/LinkPropertiesTest.java b/tests/net/common/java/android/net/LinkPropertiesTest.java
index e1c4238..b0464d9 100644
--- a/tests/net/common/java/android/net/LinkPropertiesTest.java
+++ b/tests/net/common/java/android/net/LinkPropertiesTest.java
@@ -16,6 +16,8 @@
package android.net;
+import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -31,8 +33,6 @@
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import com.android.internal.util.TestUtils;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -942,13 +942,13 @@
source.setNat64Prefix(new IpPrefix("2001:db8:1:2:64:64::/96"));
- TestUtils.assertParcelingIsLossless(source);
+ assertParcelingIsLossless(source);
}
@Test
public void testParcelUninitialized() throws Exception {
LinkProperties empty = new LinkProperties();
- TestUtils.assertParcelingIsLossless(empty);
+ assertParcelingIsLossless(empty);
}
@Test
diff --git a/tests/net/common/java/android/net/NetworkCapabilitiesTest.java b/tests/net/common/java/android/net/NetworkCapabilitiesTest.java
index 6bc7c1b..2ca0d1a 100644
--- a/tests/net/common/java/android/net/NetworkCapabilitiesTest.java
+++ b/tests/net/common/java/android/net/NetworkCapabilitiesTest.java
@@ -38,6 +38,9 @@
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.net.NetworkCapabilities.UNRESTRICTED_CAPABILITIES;
+import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
+import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
+
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -45,7 +48,6 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import android.os.Parcel;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.ArraySet;
@@ -267,9 +269,9 @@
.setUids(uids)
.addCapability(NET_CAPABILITY_EIMS)
.addCapability(NET_CAPABILITY_NOT_METERED);
- assertEqualsThroughMarshalling(netCap);
+ assertParcelingIsLossless(netCap);
netCap.setSSID(TEST_SSID);
- assertEqualsThroughMarshalling(netCap);
+ assertParcelSane(netCap, 11);
}
@Test
@@ -542,18 +544,6 @@
nc1.combineCapabilities(nc3);
}
- private void assertEqualsThroughMarshalling(NetworkCapabilities netCap) {
- Parcel p = Parcel.obtain();
- netCap.writeToParcel(p, /* flags */ 0);
- p.setDataPosition(0);
- byte[] marshalledData = p.marshall();
-
- p = Parcel.obtain();
- p.unmarshall(marshalledData, 0, marshalledData.length);
- p.setDataPosition(0);
- assertEquals(NetworkCapabilities.CREATOR.createFromParcel(p), netCap);
- }
-
@Test
public void testSet() {
NetworkCapabilities nc1 = new NetworkCapabilities();
diff --git a/tests/net/common/java/android/net/NetworkTest.java b/tests/net/common/java/android/net/NetworkTest.java
index 38bc744..11d44b8 100644
--- a/tests/net/common/java/android/net/NetworkTest.java
+++ b/tests/net/common/java/android/net/NetworkTest.java
@@ -18,13 +18,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import android.net.LocalServerSocket;
-import android.net.LocalSocket;
-import android.net.LocalSocketAddress;
-import android.net.Network;
import android.platform.test.annotations.AppModeFull;
import androidx.test.filters.SmallTest;
@@ -40,7 +37,6 @@
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.SocketException;
-import java.util.Objects;
@RunWith(AndroidJUnit4.class)
@SmallTest
@@ -123,29 +119,29 @@
Network three = new Network(3);
// None of the hashcodes are zero.
- assertNotEqual(0, one.hashCode());
- assertNotEqual(0, two.hashCode());
- assertNotEqual(0, three.hashCode());
+ assertNotEquals(0, one.hashCode());
+ assertNotEquals(0, two.hashCode());
+ assertNotEquals(0, three.hashCode());
// All the hashcodes are distinct.
- assertNotEqual(one.hashCode(), two.hashCode());
- assertNotEqual(one.hashCode(), three.hashCode());
- assertNotEqual(two.hashCode(), three.hashCode());
+ assertNotEquals(one.hashCode(), two.hashCode());
+ assertNotEquals(one.hashCode(), three.hashCode());
+ assertNotEquals(two.hashCode(), three.hashCode());
// None of the handles are zero.
- assertNotEqual(0, one.getNetworkHandle());
- assertNotEqual(0, two.getNetworkHandle());
- assertNotEqual(0, three.getNetworkHandle());
+ assertNotEquals(0, one.getNetworkHandle());
+ assertNotEquals(0, two.getNetworkHandle());
+ assertNotEquals(0, three.getNetworkHandle());
// All the handles are distinct.
- assertNotEqual(one.getNetworkHandle(), two.getNetworkHandle());
- assertNotEqual(one.getNetworkHandle(), three.getNetworkHandle());
- assertNotEqual(two.getNetworkHandle(), three.getNetworkHandle());
+ assertNotEquals(one.getNetworkHandle(), two.getNetworkHandle());
+ assertNotEquals(one.getNetworkHandle(), three.getNetworkHandle());
+ assertNotEquals(two.getNetworkHandle(), three.getNetworkHandle());
// The handles are not equal to the hashcodes.
- assertNotEqual(one.hashCode(), one.getNetworkHandle());
- assertNotEqual(two.hashCode(), two.getNetworkHandle());
- assertNotEqual(three.hashCode(), three.getNetworkHandle());
+ assertNotEquals(one.hashCode(), one.getNetworkHandle());
+ assertNotEquals(two.hashCode(), two.getNetworkHandle());
+ assertNotEquals(three.hashCode(), three.getNetworkHandle());
// Adjust as necessary to test an implementation's specific constants.
// When running with runtest, "adb logcat -s TestRunner" can be useful.
@@ -154,15 +150,11 @@
assertEquals(16290598925L, three.getNetworkHandle());
}
- private static <T> void assertNotEqual(T t1, T t2) {
- assertFalse(Objects.equals(t1, t2));
- }
-
@Test
public void testGetPrivateDnsBypassingCopy() {
final Network copy = mNetwork.getPrivateDnsBypassingCopy();
assertEquals(mNetwork.netId, copy.netId);
- assertNotEqual(copy.netId, copy.getNetIdForResolv());
- assertNotEqual(mNetwork.getNetIdForResolv(), copy.getNetIdForResolv());
+ assertNotEquals(copy.netId, copy.getNetIdForResolv());
+ assertNotEquals(mNetwork.getNetIdForResolv(), copy.getNetIdForResolv());
}
}
diff --git a/tests/net/common/java/android/net/RouteInfoTest.java b/tests/net/common/java/android/net/RouteInfoTest.java
index 2edbd40..5ce8436 100644
--- a/tests/net/common/java/android/net/RouteInfoTest.java
+++ b/tests/net/common/java/android/net/RouteInfoTest.java
@@ -18,7 +18,11 @@
import static android.net.RouteInfo.RTN_UNREACHABLE;
-import android.os.Parcel;
+import static com.android.testutils.MiscAssertsKt.assertEqualBothWays;
+import static com.android.testutils.MiscAssertsKt.assertNotEqualEitherWay;
+import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
+import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
+
import android.test.suitebuilder.annotation.SmallTest;
import junit.framework.TestCase;
@@ -109,47 +113,37 @@
assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
}
- private void assertAreEqual(Object o1, Object o2) {
- assertTrue(o1.equals(o2));
- assertTrue(o2.equals(o1));
- }
-
- private void assertAreNotEqual(Object o1, Object o2) {
- assertFalse(o1.equals(o2));
- assertFalse(o2.equals(o1));
- }
-
public void testEquals() {
// IPv4
RouteInfo r1 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
RouteInfo r2 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
- assertAreEqual(r1, r2);
+ assertEqualBothWays(r1, r2);
RouteInfo r3 = new RouteInfo(Prefix("2001:db8:ace::/49"), Address("2001:db8::1"), "wlan0");
RouteInfo r4 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::2"), "wlan0");
RouteInfo r5 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "rmnet0");
- assertAreNotEqual(r1, r3);
- assertAreNotEqual(r1, r4);
- assertAreNotEqual(r1, r5);
+ assertNotEqualEitherWay(r1, r3);
+ assertNotEqualEitherWay(r1, r4);
+ assertNotEqualEitherWay(r1, r5);
// IPv6
r1 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), "wlan0");
r2 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), "wlan0");
- assertAreEqual(r1, r2);
+ assertEqualBothWays(r1, r2);
r3 = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0");
r4 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.2"), "wlan0");
r5 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), "rmnet0");
- assertAreNotEqual(r1, r3);
- assertAreNotEqual(r1, r4);
- assertAreNotEqual(r1, r5);
+ assertNotEqualEitherWay(r1, r3);
+ assertNotEqualEitherWay(r1, r4);
+ assertNotEqualEitherWay(r1, r5);
// Interfaces (but not destinations or gateways) can be null.
r1 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), null);
r2 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), null);
r3 = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0");
- assertAreEqual(r1, r2);
- assertAreNotEqual(r1, r3);
+ assertEqualBothWays(r1, r2);
+ assertNotEqualEitherWay(r1, r3);
}
public void testHostAndDefaultRoutes() {
@@ -257,25 +251,6 @@
// No exceptions? Good.
}
- public RouteInfo passThroughParcel(RouteInfo r) {
- Parcel p = Parcel.obtain();
- RouteInfo r2 = null;
- try {
- r.writeToParcel(p, 0);
- p.setDataPosition(0);
- r2 = RouteInfo.CREATOR.createFromParcel(p);
- } finally {
- p.recycle();
- }
- assertNotNull(r2);
- return r2;
- }
-
- public void assertParcelingIsLossless(RouteInfo r) {
- RouteInfo r2 = passThroughParcel(r);
- assertEquals(r, r2);
- }
-
public void testParceling() {
RouteInfo r;
@@ -283,6 +258,6 @@
assertParcelingIsLossless(r);
r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
- assertParcelingIsLossless(r);
+ assertParcelSane(r, 6);
}
}
diff --git a/tests/net/common/java/android/net/StaticIpConfigurationTest.java b/tests/net/common/java/android/net/StaticIpConfigurationTest.java
index 5096be2..b5f23bf 100644
--- a/tests/net/common/java/android/net/StaticIpConfigurationTest.java
+++ b/tests/net/common/java/android/net/StaticIpConfigurationTest.java
@@ -18,6 +18,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -34,7 +35,6 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-import java.util.Objects;
@RunWith(AndroidJUnit4.class)
@SmallTest
@@ -61,10 +61,6 @@
assertEquals(0, s.dnsServers.size());
}
- private static <T> void assertNotEquals(T t1, T t2) {
- assertFalse(Objects.equals(t1, t2));
- }
-
private StaticIpConfiguration makeTestObject() {
StaticIpConfiguration s = new StaticIpConfiguration();
s.ipAddress = ADDR;
diff --git a/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java b/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java
index 0ce7c91..f4f804a 100644
--- a/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java
+++ b/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java
@@ -16,6 +16,8 @@
package android.net.apf;
+import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -24,9 +26,6 @@
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import com.android.internal.util.ParcelableTestUtil;
-import com.android.internal.util.TestUtils;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,9 +39,7 @@
assertEquals(456, caps.maximumApfProgramSize);
assertEquals(789, caps.apfPacketFormat);
- ParcelableTestUtil.assertFieldCountEquals(3, ApfCapabilities.class);
-
- TestUtils.assertParcelingIsLossless(caps);
+ assertParcelSane(caps, 3);
}
@Test
diff --git a/tests/net/common/java/android/net/metrics/ApfProgramEventTest.kt b/tests/net/common/java/android/net/metrics/ApfProgramEventTest.kt
index 8d055c9..0b7b740 100644
--- a/tests/net/common/java/android/net/metrics/ApfProgramEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/ApfProgramEventTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics;
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
@@ -30,11 +28,6 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class ApfProgramEventTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
private infix fun Int.hasFlag(flag: Int) = (this and (1 shl flag)) != 0
@Test
@@ -55,7 +48,7 @@
assertEquals(5, apfProgramEvent.programLength)
assertEquals(ApfProgramEvent.flagsFor(true, true), apfProgramEvent.flags)
- testParcel(apfProgramEvent, 6)
+ assertParcelSane(apfProgramEvent, 6)
}
@Test
diff --git a/tests/net/common/java/android/net/metrics/ApfStatsTest.kt b/tests/net/common/java/android/net/metrics/ApfStatsTest.kt
index f8eb40c..46a8c8e 100644
--- a/tests/net/common/java/android/net/metrics/ApfStatsTest.kt
+++ b/tests/net/common/java/android/net/metrics/ApfStatsTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -28,11 +26,6 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class ApfStatsTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
@Test
fun testBuilderAndParcel() {
val apfStats = ApfStats.Builder()
@@ -59,6 +52,6 @@
assertEquals(8, apfStats.programUpdatesAllowingMulticast)
assertEquals(9, apfStats.maxProgramSize)
- testParcel(apfStats, 10)
+ assertParcelSane(apfStats, 10)
}
}
diff --git a/tests/net/common/java/android/net/metrics/DhcpClientEventTest.kt b/tests/net/common/java/android/net/metrics/DhcpClientEventTest.kt
index 36e9f8c..8d7a9c4 100644
--- a/tests/net/common/java/android/net/metrics/DhcpClientEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/DhcpClientEventTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -30,11 +28,6 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class DhcpClientEventTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
@Test
fun testBuilderAndParcel() {
val dhcpClientEvent = DhcpClientEvent.Builder()
@@ -45,6 +38,6 @@
assertEquals(FAKE_MESSAGE, dhcpClientEvent.msg)
assertEquals(Integer.MAX_VALUE, dhcpClientEvent.durationMs)
- testParcel(dhcpClientEvent, 2)
+ assertParcelSane(dhcpClientEvent, 2)
}
}
diff --git a/tests/net/common/java/android/net/metrics/DhcpErrorEventTest.kt b/tests/net/common/java/android/net/metrics/DhcpErrorEventTest.kt
index e9d5e6d..236f72e 100644
--- a/tests/net/common/java/android/net/metrics/DhcpErrorEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/DhcpErrorEventTest.kt
@@ -1,10 +1,10 @@
package android.net.metrics
-import android.net.metrics.DhcpErrorEvent.errorCodeWithOption
import android.net.metrics.DhcpErrorEvent.DHCP_INVALID_OPTION_LENGTH
+import android.net.metrics.DhcpErrorEvent.errorCodeWithOption
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.TestUtils.parcelingRoundTrip
+import com.android.testutils.parcelingRoundTrip
import java.lang.reflect.Modifier
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
@@ -62,4 +62,4 @@
fun testToString_InvalidErrorCode() {
assertNotNull(DhcpErrorEvent(TEST_ERROR_CODE).toString())
}
-}
\ No newline at end of file
+}
diff --git a/tests/net/common/java/android/net/metrics/IpManagerEventTest.kt b/tests/net/common/java/android/net/metrics/IpManagerEventTest.kt
index 5144ca5..64be508 100644
--- a/tests/net/common/java/android/net/metrics/IpManagerEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/IpManagerEventTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -28,11 +26,6 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class IpManagerEventTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
@Test
fun testConstructorAndParcel() {
(IpManagerEvent.PROVISIONING_OK..IpManagerEvent.ERROR_INTERFACE_NOT_FOUND).forEach {
@@ -40,7 +33,7 @@
assertEquals(it, ipManagerEvent.eventType)
assertEquals(Long.MAX_VALUE, ipManagerEvent.durationMs)
- testParcel(ipManagerEvent, 2)
+ assertParcelSane(ipManagerEvent, 2)
}
}
}
diff --git a/tests/net/common/java/android/net/metrics/IpReachabilityEventTest.kt b/tests/net/common/java/android/net/metrics/IpReachabilityEventTest.kt
index d76ebf6..55b5e49 100644
--- a/tests/net/common/java/android/net/metrics/IpReachabilityEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/IpReachabilityEventTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -28,18 +26,13 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class IpReachabilityEventTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
@Test
fun testConstructorAndParcel() {
(IpReachabilityEvent.PROBE..IpReachabilityEvent.PROVISIONING_LOST_ORGANIC).forEach {
val ipReachabilityEvent = IpReachabilityEvent(it)
assertEquals(it, ipReachabilityEvent.eventType)
- testParcel(ipReachabilityEvent, 1)
+ assertParcelSane(ipReachabilityEvent, 1)
}
}
}
diff --git a/tests/net/common/java/android/net/metrics/NetworkEventTest.kt b/tests/net/common/java/android/net/metrics/NetworkEventTest.kt
index 8b52e81..41430b0 100644
--- a/tests/net/common/java/android/net/metrics/NetworkEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/NetworkEventTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -28,11 +26,6 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class NetworkEventTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
@Test
fun testConstructorAndParcel() {
(NetworkEvent.NETWORK_CONNECTED..NetworkEvent.NETWORK_PARTIAL_CONNECTIVITY).forEach {
@@ -44,7 +37,7 @@
assertEquals(it, networkEvent.eventType)
assertEquals(Long.MAX_VALUE, networkEvent.durationMs)
- testParcel(networkEvent, 2)
+ assertParcelSane(networkEvent, 2)
}
}
}
diff --git a/tests/net/common/java/android/net/metrics/RaEventTest.kt b/tests/net/common/java/android/net/metrics/RaEventTest.kt
index f38d328..d9b7203 100644
--- a/tests/net/common/java/android/net/metrics/RaEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/RaEventTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -30,11 +28,6 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class RaEventTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
@Test
fun testConstructorAndParcel() {
var raEvent = RaEvent.Builder().build()
@@ -74,6 +67,6 @@
assertEquals(5, raEvent.rdnssLifetime)
assertEquals(6, raEvent.dnsslLifetime)
- testParcel(raEvent, 6)
+ assertParcelSane(raEvent, 6)
}
}
diff --git a/tests/net/common/java/android/net/metrics/ValidationProbeEventTest.kt b/tests/net/common/java/android/net/metrics/ValidationProbeEventTest.kt
index c0cef8f..51c0d41 100644
--- a/tests/net/common/java/android/net/metrics/ValidationProbeEventTest.kt
+++ b/tests/net/common/java/android/net/metrics/ValidationProbeEventTest.kt
@@ -16,11 +16,9 @@
package android.net.metrics
-import android.os.Parcelable
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
-import com.android.internal.util.ParcelableTestUtil
-import com.android.internal.util.TestUtils
+import com.android.testutils.assertParcelSane
import java.lang.reflect.Modifier
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
@@ -33,11 +31,6 @@
@RunWith(AndroidJUnit4::class)
@SmallTest
class ValidationProbeEventTest {
- private fun <T: Parcelable> testParcel(obj: T, fieldCount: Int) {
- ParcelableTestUtil.assertFieldCountEquals(fieldCount, obj::class.java)
- TestUtils.assertParcelingIsLossless(obj)
- }
-
private infix fun Int.hasType(type: Int) = (type and this) == type
@Test
@@ -58,7 +51,7 @@
assertTrue(validationProbeEvent.probeType hasType FIRST_VALIDATION)
assertEquals(ValidationProbeEvent.DNS_SUCCESS, validationProbeEvent.returnCode)
- testParcel(validationProbeEvent, 3)
+ assertParcelSane(validationProbeEvent, 3)
}
@Test
diff --git a/tests/net/java/android/app/usage/NetworkStatsManagerTest.java b/tests/net/java/android/app/usage/NetworkStatsManagerTest.java
index fd555c1..899295a 100644
--- a/tests/net/java/android/app/usage/NetworkStatsManagerTest.java
+++ b/tests/net/java/android/app/usage/NetworkStatsManagerTest.java
@@ -202,8 +202,7 @@
assertFalse(stats.hasNextBucket());
}
- private void assertBucketMatches(Entry expected,
- NetworkStats.Bucket actual) {
+ private void assertBucketMatches(Entry expected, NetworkStats.Bucket actual) {
assertEquals(expected.uid, actual.getUid());
assertEquals(expected.rxBytes, actual.getRxBytes());
assertEquals(expected.rxPackets, actual.getRxPackets());
diff --git a/tests/net/java/android/net/IpSecConfigTest.java b/tests/net/java/android/net/IpSecConfigTest.java
index 215506c..c9888b2 100644
--- a/tests/net/java/android/net/IpSecConfigTest.java
+++ b/tests/net/java/android/net/IpSecConfigTest.java
@@ -16,12 +16,12 @@
package android.net;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
+import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
-import android.os.Parcel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
import androidx.test.filters.SmallTest;
@@ -89,23 +89,15 @@
IpSecConfig original = getSampleConfig();
IpSecConfig copy = new IpSecConfig(original);
- assertTrue(IpSecConfig.equals(original, copy));
- assertFalse(original == copy);
+ assertEquals(original, copy);
+ assertNotSame(original, copy);
}
@Test
- public void testParcelUnparcel() throws Exception {
+ public void testParcelUnparcel() {
assertParcelingIsLossless(new IpSecConfig());
IpSecConfig c = getSampleConfig();
- assertParcelingIsLossless(c);
- }
-
- private void assertParcelingIsLossless(IpSecConfig ci) throws Exception {
- Parcel p = Parcel.obtain();
- ci.writeToParcel(p, 0);
- p.setDataPosition(0);
- IpSecConfig co = IpSecConfig.CREATOR.createFromParcel(p);
- assertTrue(IpSecConfig.equals(co, ci));
+ assertParcelSane(c, 15);
}
}
diff --git a/tests/net/java/android/net/IpSecTransformTest.java b/tests/net/java/android/net/IpSecTransformTest.java
index 2308a3c..424f23d 100644
--- a/tests/net/java/android/net/IpSecTransformTest.java
+++ b/tests/net/java/android/net/IpSecTransformTest.java
@@ -16,8 +16,8 @@
package android.net;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import androidx.test.filters.SmallTest;
@@ -43,7 +43,7 @@
config.setSpiResourceId(1985);
IpSecTransform postModification = new IpSecTransform(null, config);
- assertFalse(IpSecTransform.equals(preModification, postModification));
+ assertNotEquals(preModification, postModification);
}
@Test
@@ -57,6 +57,6 @@
IpSecTransform config1 = new IpSecTransform(null, config);
IpSecTransform config2 = new IpSecTransform(null, config);
- assertTrue(IpSecTransform.equals(config1, config2));
+ assertEquals(config1, config2);
}
}
diff --git a/tests/net/java/android/net/TcpKeepalivePacketDataTest.java b/tests/net/java/android/net/TcpKeepalivePacketDataTest.java
index 583d3fd..5cb0d7e 100644
--- a/tests/net/java/android/net/TcpKeepalivePacketDataTest.java
+++ b/tests/net/java/android/net/TcpKeepalivePacketDataTest.java
@@ -16,14 +16,14 @@
package android.net;
+import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
+
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import android.net.SocketKeepalive.InvalidPacketException;
-import com.android.internal.util.TestUtils;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -79,7 +79,7 @@
assertEquals(testInfo.tos, resultData.ipTos);
assertEquals(testInfo.ttl, resultData.ipTtl);
- TestUtils.assertParcelingIsLossless(resultData);
+ assertParcelingIsLossless(resultData);
final byte[] packet = resultData.getPacket();
// IP version and IHL
diff --git a/tests/net/java/android/net/shared/InitialConfigurationTest.java b/tests/net/java/android/net/shared/InitialConfigurationTest.java
index 2fb8b19..17f8324 100644
--- a/tests/net/java/android/net/shared/InitialConfigurationTest.java
+++ b/tests/net/java/android/net/shared/InitialConfigurationTest.java
@@ -18,7 +18,7 @@
import static android.net.InetAddresses.parseNumericAddress;
-import static com.android.internal.util.ParcelableTestUtil.assertFieldCountEquals;
+import static com.android.testutils.MiscAssertsKt.assertFieldCountEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
diff --git a/tests/net/java/android/net/shared/IpConfigurationParcelableUtilTest.java b/tests/net/java/android/net/shared/IpConfigurationParcelableUtilTest.java
index f9dbdc7..f987389 100644
--- a/tests/net/java/android/net/shared/IpConfigurationParcelableUtilTest.java
+++ b/tests/net/java/android/net/shared/IpConfigurationParcelableUtilTest.java
@@ -20,7 +20,7 @@
import static android.net.shared.IpConfigurationParcelableUtil.fromStableParcelable;
import static android.net.shared.IpConfigurationParcelableUtil.toStableParcelable;
-import static com.android.internal.util.ParcelableTestUtil.assertFieldCountEquals;
+import static com.android.testutils.MiscAssertsKt.assertFieldCountEquals;
import static org.junit.Assert.assertEquals;
diff --git a/tests/net/java/android/net/shared/ProvisioningConfigurationTest.java b/tests/net/java/android/net/shared/ProvisioningConfigurationTest.java
index 382afe0..7079a28 100644
--- a/tests/net/java/android/net/shared/ProvisioningConfigurationTest.java
+++ b/tests/net/java/android/net/shared/ProvisioningConfigurationTest.java
@@ -19,7 +19,7 @@
import static android.net.InetAddresses.parseNumericAddress;
import static android.net.shared.ProvisioningConfiguration.fromStableParcelable;
-import static com.android.internal.util.ParcelableTestUtil.assertFieldCountEquals;
+import static com.android.testutils.MiscAssertsKt.assertFieldCountEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
diff --git a/tests/net/java/com/android/internal/util/RingBufferTest.java b/tests/net/java/com/android/internal/util/RingBufferTest.java
index eff334f..d06095a 100644
--- a/tests/net/java/com/android/internal/util/RingBufferTest.java
+++ b/tests/net/java/com/android/internal/util/RingBufferTest.java
@@ -16,6 +16,7 @@
package com.android.internal.util;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@@ -25,9 +26,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.util.Arrays;
-import java.util.Objects;
-
@SmallTest
@RunWith(AndroidJUnit4.class)
public class RingBufferTest {
@@ -36,7 +34,7 @@
public void testEmptyRingBuffer() {
RingBuffer<String> buffer = new RingBuffer<>(String.class, 100);
- assertArraysEqual(new String[0], buffer.toArray());
+ assertArrayEquals(new String[0], buffer.toArray());
}
@Test
@@ -65,7 +63,7 @@
buffer.append("e");
String[] expected = {"a", "b", "c", "d", "e"};
- assertArraysEqual(expected, buffer.toArray());
+ assertArrayEquals(expected, buffer.toArray());
}
@Test
@@ -73,19 +71,19 @@
RingBuffer<String> buffer = new RingBuffer<>(String.class, 1);
buffer.append("a");
- assertArraysEqual(new String[]{"a"}, buffer.toArray());
+ assertArrayEquals(new String[]{"a"}, buffer.toArray());
buffer.append("b");
- assertArraysEqual(new String[]{"b"}, buffer.toArray());
+ assertArrayEquals(new String[]{"b"}, buffer.toArray());
buffer.append("c");
- assertArraysEqual(new String[]{"c"}, buffer.toArray());
+ assertArrayEquals(new String[]{"c"}, buffer.toArray());
buffer.append("d");
- assertArraysEqual(new String[]{"d"}, buffer.toArray());
+ assertArrayEquals(new String[]{"d"}, buffer.toArray());
buffer.append("e");
- assertArraysEqual(new String[]{"e"}, buffer.toArray());
+ assertArrayEquals(new String[]{"e"}, buffer.toArray());
}
@Test
@@ -100,7 +98,7 @@
buffer.append("e");
String[] expected1 = {"a", "b", "c", "d", "e"};
- assertArraysEqual(expected1, buffer.toArray());
+ assertArrayEquals(expected1, buffer.toArray());
String[] expected2 = new String[capacity];
int firstIndex = 0;
@@ -111,22 +109,22 @@
buffer.append("x");
expected2[i] = "x";
}
- assertArraysEqual(expected2, buffer.toArray());
+ assertArrayEquals(expected2, buffer.toArray());
buffer.append("x");
expected2[firstIndex] = "x";
- assertArraysEqual(expected2, buffer.toArray());
+ assertArrayEquals(expected2, buffer.toArray());
for (int i = 0; i < 10; i++) {
for (String s : expected2) {
buffer.append(s);
}
}
- assertArraysEqual(expected2, buffer.toArray());
+ assertArrayEquals(expected2, buffer.toArray());
buffer.append("a");
expected2[lastIndex] = "a";
- assertArraysEqual(expected2, buffer.toArray());
+ assertArrayEquals(expected2, buffer.toArray());
}
@Test
@@ -143,7 +141,7 @@
expected[i] = new DummyClass1();
expected[i].x = capacity * i;
}
- assertArraysEqual(expected, buffer.toArray());
+ assertArrayEquals(expected, buffer.toArray());
for (int i = 0; i < capacity; ++i) {
if (actual[i] != buffer.getNextSlot()) {
@@ -177,18 +175,4 @@
}
private static final class DummyClass3 {}
-
- static <T> void assertArraysEqual(T[] expected, T[] got) {
- if (expected.length != got.length) {
- fail(Arrays.toString(expected) + " and " + Arrays.toString(got)
- + " did not have the same length");
- }
-
- for (int i = 0; i < expected.length; i++) {
- if (!Objects.equals(expected[i], got[i])) {
- fail(Arrays.toString(expected) + " and " + Arrays.toString(got)
- + " were not equal");
- }
- }
- }
}
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 557b7e9..51d9475 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -68,7 +68,15 @@
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
import static android.net.RouteInfo.RTN_UNREACHABLE;
-import static org.junit.Assert.assertArrayEquals;
+import static com.android.testutils.ConcurrentUtilsKt.await;
+import static com.android.testutils.ConcurrentUtilsKt.durationOf;
+import static com.android.testutils.HandlerUtilsKt.waitForIdleSerialExecutor;
+import static com.android.testutils.MiscAssertsKt.assertContainsExactly;
+import static com.android.testutils.MiscAssertsKt.assertEmpty;
+import static com.android.testutils.MiscAssertsKt.assertLength;
+import static com.android.testutils.MiscAssertsKt.assertRunsInAtMost;
+import static com.android.testutils.MiscAssertsKt.assertThrows;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -194,6 +202,7 @@
import com.android.server.net.NetworkPolicyManagerInternal;
import com.android.server.net.NetworkStatsFactory;
import com.android.testutils.HandlerUtilsKt;
+import com.android.testutils.ThrowingConsumer;
import org.junit.After;
import org.junit.Before;
@@ -2567,10 +2576,10 @@
.build();
Class<IllegalArgumentException> expected = IllegalArgumentException.class;
- assertException(() -> { mCm.requestNetwork(request1, new NetworkCallback()); }, expected);
- assertException(() -> { mCm.requestNetwork(request1, pendingIntent); }, expected);
- assertException(() -> { mCm.requestNetwork(request2, new NetworkCallback()); }, expected);
- assertException(() -> { mCm.requestNetwork(request2, pendingIntent); }, expected);
+ assertThrows(expected, () -> mCm.requestNetwork(request1, new NetworkCallback()));
+ assertThrows(expected, () -> mCm.requestNetwork(request1, pendingIntent));
+ assertThrows(expected, () -> mCm.requestNetwork(request2, new NetworkCallback()));
+ assertThrows(expected, () -> mCm.requestNetwork(request2, pendingIntent));
}
@Test
@@ -3482,7 +3491,7 @@
};
}
- assertTimeLimit("Registering callbacks", REGISTER_TIME_LIMIT_MS, () -> {
+ assertRunsInAtMost("Registering callbacks", REGISTER_TIME_LIMIT_MS, () -> {
for (NetworkCallback cb : callbacks) {
mCm.registerNetworkCallback(request, cb);
}
@@ -3495,7 +3504,7 @@
mCellNetworkAgent.connect(false);
long onAvailableDispatchingDuration = durationOf(() -> {
- awaitLatch(availableLatch, 10 * CONNECT_TIME_LIMIT_MS);
+ await(availableLatch, 10 * CONNECT_TIME_LIMIT_MS);
});
Log.d(TAG, String.format("Dispatched %d of %d onAvailable callbacks in %dms",
NUM_REQUESTS - availableLatch.getCount(), NUM_REQUESTS,
@@ -3510,7 +3519,7 @@
mWiFiNetworkAgent.connect(false);
long onLostDispatchingDuration = durationOf(() -> {
- awaitLatch(losingLatch, 10 * SWITCH_TIME_LIMIT_MS);
+ await(losingLatch, 10 * SWITCH_TIME_LIMIT_MS);
});
Log.d(TAG, String.format("Dispatched %d of %d onLosing callbacks in %dms",
NUM_REQUESTS - losingLatch.getCount(), NUM_REQUESTS, onLostDispatchingDuration));
@@ -3518,33 +3527,13 @@
NUM_REQUESTS, onLostDispatchingDuration, SWITCH_TIME_LIMIT_MS),
onLostDispatchingDuration <= SWITCH_TIME_LIMIT_MS);
- assertTimeLimit("Unregistering callbacks", UNREGISTER_TIME_LIMIT_MS, () -> {
+ assertRunsInAtMost("Unregistering callbacks", UNREGISTER_TIME_LIMIT_MS, () -> {
for (NetworkCallback cb : callbacks) {
mCm.unregisterNetworkCallback(cb);
}
});
}
- private long durationOf(Runnable fn) {
- long startTime = SystemClock.elapsedRealtime();
- fn.run();
- return SystemClock.elapsedRealtime() - startTime;
- }
-
- private void assertTimeLimit(String descr, long timeLimit, Runnable fn) {
- long timeTaken = durationOf(fn);
- String msg = String.format("%s: took %dms, limit was %dms", descr, timeTaken, timeLimit);
- Log.d(TAG, msg);
- assertTrue(msg, timeTaken <= timeLimit);
- }
-
- private boolean awaitLatch(CountDownLatch l, long timeoutMs) {
- try {
- return l.await(timeoutMs, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {}
- return false;
- }
-
@Test
public void testMobileDataAlwaysOn() throws Exception {
final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
@@ -4105,7 +4094,7 @@
}
public void assertNoCallback() {
- HandlerUtilsKt.waitForIdleSerialExecutor(mExecutor, TIMEOUT_MS);
+ waitForIdleSerialExecutor(mExecutor, TIMEOUT_MS);
CallbackValue cv = mCallbacks.peek();
assertNull("Unexpected callback: " + cv, cv);
}
@@ -4244,11 +4233,6 @@
callback3.expectStopped();
}
- @FunctionalInterface
- private interface ThrowingConsumer<T> {
- void accept(T t) throws Exception;
- }
-
// Helper method to prepare the executor and run test
private void runTestWithSerialExecutors(ThrowingConsumer<Executor> functor) throws Exception {
final ExecutorService executorSingleThread = Executors.newSingleThreadExecutor();
@@ -4823,17 +4807,17 @@
assertNull(mCm.getLinkProperties(TYPE_NONE));
assertFalse(mCm.isNetworkSupported(TYPE_NONE));
- assertException(() -> { mCm.networkCapabilitiesForType(TYPE_NONE); },
- IllegalArgumentException.class);
+ assertThrows(IllegalArgumentException.class,
+ () -> { mCm.networkCapabilitiesForType(TYPE_NONE); });
Class<UnsupportedOperationException> unsupported = UnsupportedOperationException.class;
- assertException(() -> { mCm.startUsingNetworkFeature(TYPE_WIFI, ""); }, unsupported);
- assertException(() -> { mCm.stopUsingNetworkFeature(TYPE_WIFI, ""); }, unsupported);
+ assertThrows(unsupported, () -> { mCm.startUsingNetworkFeature(TYPE_WIFI, ""); });
+ assertThrows(unsupported, () -> { mCm.stopUsingNetworkFeature(TYPE_WIFI, ""); });
// TODO: let test context have configuration application target sdk version
// and test that pre-M requesting for TYPE_NONE sends back APN_REQUEST_FAILED
- assertException(() -> { mCm.startUsingNetworkFeature(TYPE_NONE, ""); }, unsupported);
- assertException(() -> { mCm.stopUsingNetworkFeature(TYPE_NONE, ""); }, unsupported);
- assertException(() -> { mCm.requestRouteToHostAddress(TYPE_NONE, null); }, unsupported);
+ assertThrows(unsupported, () -> { mCm.startUsingNetworkFeature(TYPE_NONE, ""); });
+ assertThrows(unsupported, () -> { mCm.stopUsingNetworkFeature(TYPE_NONE, ""); });
+ assertThrows(unsupported, () -> { mCm.requestRouteToHostAddress(TYPE_NONE, null); });
}
@Test
@@ -5095,11 +5079,11 @@
ResolverParamsParcel resolvrParams = mResolverParamsParcelCaptor.getValue();
assertEquals(2, resolvrParams.tlsServers.length);
assertTrue(ArrayUtils.containsAll(resolvrParams.tlsServers,
- new String[]{"2001:db8::1", "192.0.2.1"}));
+ new String[] { "2001:db8::1", "192.0.2.1" }));
// Opportunistic mode.
assertEquals(2, resolvrParams.tlsServers.length);
assertTrue(ArrayUtils.containsAll(resolvrParams.tlsServers,
- new String[]{"2001:db8::1", "192.0.2.1"}));
+ new String[] { "2001:db8::1", "192.0.2.1" }));
reset(mMockDnsResolver);
cellNetworkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
cellNetworkCallback.expectCallback(CallbackState.NETWORK_CAPABILITIES,
@@ -5117,7 +5101,7 @@
resolvrParams = mResolverParamsParcelCaptor.getValue();
assertEquals(2, resolvrParams.servers.length);
assertTrue(ArrayUtils.containsAll(resolvrParams.servers,
- new String[]{"2001:db8::1", "192.0.2.1"}));
+ new String[] { "2001:db8::1", "192.0.2.1" }));
reset(mMockDnsResolver);
cellNetworkCallback.assertNoCallback();
@@ -5127,10 +5111,10 @@
resolvrParams = mResolverParamsParcelCaptor.getValue();
assertEquals(2, resolvrParams.servers.length);
assertTrue(ArrayUtils.containsAll(resolvrParams.servers,
- new String[]{"2001:db8::1", "192.0.2.1"}));
+ new String[] { "2001:db8::1", "192.0.2.1" }));
assertEquals(2, resolvrParams.tlsServers.length);
assertTrue(ArrayUtils.containsAll(resolvrParams.tlsServers,
- new String[]{"2001:db8::1", "192.0.2.1"}));
+ new String[] { "2001:db8::1", "192.0.2.1" }));
reset(mMockDnsResolver);
cellNetworkCallback.assertNoCallback();
@@ -5265,29 +5249,6 @@
assertTrue(lp.getDnsServers().containsAll(dnsServers));
}
- private static <T> void assertEmpty(T[] ts) {
- int length = ts.length;
- assertEquals("expected empty array, but length was " + length, 0, length);
- }
-
- private static <T> void assertLength(int expected, T[] got) {
- int length = got.length;
- assertEquals(String.format("expected array of length %s, but length was %s for %s",
- expected, length, Arrays.toString(got)), expected, length);
- }
-
- private static <T> void assertException(Runnable block, Class<T> expected) {
- try {
- block.run();
- fail("Expected exception of type " + expected);
- } catch (Exception got) {
- if (!got.getClass().equals(expected)) {
- fail("Expected exception of type " + expected + " but got " + got);
- }
- return;
- }
- }
-
@Test
public void testVpnNetworkActive() {
final int uid = Process.myUid();
@@ -6484,14 +6445,6 @@
return vpnNetworkAgent;
}
- private void assertContainsExactly(int[] actual, int... expected) {
- int[] sortedActual = Arrays.copyOf(actual, actual.length);
- int[] sortedExpected = Arrays.copyOf(expected, expected.length);
- Arrays.sort(sortedActual);
- Arrays.sort(sortedExpected);
- assertArrayEquals(sortedExpected, sortedActual);
- }
-
private static PackageInfo buildPackageInfo(boolean hasSystemPermission, int uid) {
final PackageInfo packageInfo = new PackageInfo();
packageInfo.requestedPermissions = new String[0];
diff --git a/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java b/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java
index e4117b8..aef9386 100644
--- a/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java
+++ b/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java
@@ -19,8 +19,9 @@
import static android.net.metrics.INetdEventListener.EVENT_GETADDRINFO;
import static android.net.metrics.INetdEventListener.EVENT_GETHOSTBYNAME;
+import static com.android.testutils.MiscAssertsKt.assertStringContains;
+
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -111,15 +112,15 @@
String[] events2 = remove(listNetdEvent(), baseline);
int expectedLength2 = uids.length + 1; // +1 for the WakeupStats line
assertEquals(expectedLength2, events2.length);
- assertContains(events2[0], "WakeupStats");
- assertContains(events2[0], "wlan0");
- assertContains(events2[0], "0x800");
- assertContains(events2[0], "0x86dd");
+ assertStringContains(events2[0], "WakeupStats");
+ assertStringContains(events2[0], "wlan0");
+ assertStringContains(events2[0], "0x800");
+ assertStringContains(events2[0], "0x86dd");
for (int i = 0; i < uids.length; i++) {
String got = events2[i+1];
- assertContains(got, "WakeupEvent");
- assertContains(got, "wlan0");
- assertContains(got, "uid: " + uids[i]);
+ assertStringContains(got, "WakeupEvent");
+ assertStringContains(got, "wlan0");
+ assertStringContains(got, "uid: " + uids[i]);
}
int uid = 20000;
@@ -131,13 +132,13 @@
String[] events3 = remove(listNetdEvent(), baseline);
int expectedLength3 = BUFFER_LENGTH + 1; // +1 for the WakeupStats line
assertEquals(expectedLength3, events3.length);
- assertContains(events2[0], "WakeupStats");
- assertContains(events2[0], "wlan0");
+ assertStringContains(events2[0], "WakeupStats");
+ assertStringContains(events2[0], "wlan0");
for (int i = 1; i < expectedLength3; i++) {
String got = events3[i];
- assertContains(got, "WakeupEvent");
- assertContains(got, "wlan0");
- assertContains(got, "uid: " + uid);
+ assertStringContains(got, "WakeupEvent");
+ assertStringContains(got, "wlan0");
+ assertStringContains(got, "uid: " + uid);
}
uid = 45678;
@@ -145,9 +146,9 @@
String[] events4 = remove(listNetdEvent(), baseline);
String lastEvent = events4[events4.length - 1];
- assertContains(lastEvent, "WakeupEvent");
- assertContains(lastEvent, "wlan0");
- assertContains(lastEvent, "uid: " + uid);
+ assertStringContains(lastEvent, "WakeupEvent");
+ assertStringContains(lastEvent, "wlan0");
+ assertStringContains(lastEvent, "uid: " + uid);
}
@Test
@@ -529,10 +530,6 @@
return buffer.toString().split("\\n");
}
- static void assertContains(String got, String want) {
- assertTrue(got + " did not contain \"" + want + "\"", got.contains(want));
- }
-
static <T> T[] remove(T[] array, T[] filtered) {
List<T> c = Arrays.asList(filtered);
int next = 0;
diff --git a/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java b/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java
index 762b76c..9931aec 100644
--- a/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java
+++ b/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java
@@ -25,6 +25,7 @@
import static android.provider.Settings.Global.TETHER_OFFLOAD_DISABLED;
import static com.android.server.connectivity.tethering.OffloadHardwareInterface.ForwardedStats;
+import static com.android.testutils.MiscAssertsKt.assertContainsAll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -244,7 +245,7 @@
inOrder.verify(mHardware, times(1)).setLocalPrefixes(mStringArrayCaptor.capture());
ArrayList<String> localPrefixes = mStringArrayCaptor.getValue();
assertEquals(4, localPrefixes.size());
- assertArrayListContains(localPrefixes,
+ assertContainsAll(localPrefixes,
"127.0.0.0/8", "192.0.2.0/24", "fe80::/64", "2001:db8::/64");
inOrder.verifyNoMoreInteractions();
@@ -360,7 +361,7 @@
inOrder.verify(mHardware, times(1)).setLocalPrefixes(mStringArrayCaptor.capture());
localPrefixes = mStringArrayCaptor.getValue();
assertEquals(6, localPrefixes.size());
- assertArrayListContains(localPrefixes,
+ assertContainsAll(localPrefixes,
"127.0.0.0/8", "192.0.2.0/24", "fe80::/64", "2001:db8::/64",
"2001:db8::6173:7369:676e:6564/128", "2001:db8::7261:6e64:6f6d/128");
// The relevant parts of the LinkProperties have not changed, but at the
@@ -717,7 +718,7 @@
verify(mHardware, times(1)).setLocalPrefixes(mStringArrayCaptor.capture());
ArrayList<String> localPrefixes = mStringArrayCaptor.getValue();
assertEquals(4, localPrefixes.size());
- assertArrayListContains(localPrefixes,
+ assertContainsAll(localPrefixes,
// TODO: The logic to find and exclude downstream IP prefixes
// is currently in Tethering's OffloadWrapper but must be moved
// into OffloadController proper. After this, also check for:
@@ -730,9 +731,4 @@
verifyNoMoreInteractions(mHardware);
}
- private static void assertArrayListContains(ArrayList<String> list, String... elems) {
- for (String element : elems) {
- assertTrue(element + " not in list", list.contains(element));
- }
- }
}
diff --git a/tests/net/java/com/android/server/net/NetworkStatsCollectionTest.java b/tests/net/java/com/android/server/net/NetworkStatsCollectionTest.java
index 9b4f49c..8f90f13 100644
--- a/tests/net/java/com/android/server/net/NetworkStatsCollectionTest.java
+++ b/tests/net/java/com/android/server/net/NetworkStatsCollectionTest.java
@@ -29,6 +29,7 @@
import static com.android.server.net.NetworkStatsCollection.multiplySafe;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -43,7 +44,6 @@
import android.os.UserHandle;
import android.telephony.SubscriptionPlan;
import android.telephony.TelephonyManager;
-import android.test.MoreAsserts;
import android.text.format.DateUtils;
import android.util.RecurrenceRule;
@@ -240,11 +240,11 @@
60 * MINUTE_IN_MILLIS, entry);
// Verify the set of relevant UIDs for each access level.
- MoreAsserts.assertEquals(new int[] { myUid },
+ assertArrayEquals(new int[] { myUid },
collection.getRelevantUids(NetworkStatsAccess.Level.DEFAULT));
- MoreAsserts.assertEquals(new int[] { Process.SYSTEM_UID, myUid, otherUidInSameUser },
+ assertArrayEquals(new int[] { Process.SYSTEM_UID, myUid, otherUidInSameUser },
collection.getRelevantUids(NetworkStatsAccess.Level.USER));
- MoreAsserts.assertEquals(
+ assertArrayEquals(
new int[] { Process.SYSTEM_UID, myUid, otherUidInSameUser, uidInDifferentUser },
collection.getRelevantUids(NetworkStatsAccess.Level.DEVICE));
diff --git a/tests/net/util/Android.bp b/tests/net/util/Android.bp
deleted file mode 100644
index d8c502d..0000000
--- a/tests/net/util/Android.bp
+++ /dev/null
@@ -1,30 +0,0 @@
-//
-// Copyright (C) 2019 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-// Common utilities for network tests.
-java_library {
- name: "frameworks-net-testutils",
- srcs: ["java/**/*.java"],
- // test_current to be also appropriate for CTS tests
- sdk_version: "test_current",
- static_libs: [
- "androidx.annotation_annotation",
- "junit",
- ],
- libs: [
- "android.test.base.stubs",
- ],
-}
\ No newline at end of file
diff --git a/tests/net/util/java/com/android/internal/util/ParcelableTestUtil.java b/tests/net/util/java/com/android/internal/util/ParcelableTestUtil.java
deleted file mode 100644
index 87537b9..0000000
--- a/tests/net/util/java/com/android/internal/util/ParcelableTestUtil.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.util;
-
-import static org.junit.Assert.assertEquals;
-
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-
-/**
- * Utility classes to write tests for stable AIDL parceling/unparceling
- */
-public final class ParcelableTestUtil {
-
- /**
- * Verifies that the number of nonstatic fields in a class equals a given count.
- *
- * <p>This assertion serves as a reminder to update test code around it if fields are added
- * after the test is written.
- * @param count Expected number of nonstatic fields in the class.
- * @param clazz Class to test.
- */
- public static <T> void assertFieldCountEquals(int count, Class<T> clazz) {
- assertEquals(count, Arrays.stream(clazz.getDeclaredFields())
- .filter(f -> !Modifier.isStatic(f.getModifiers())).count());
- }
-}
diff --git a/tests/net/util/java/com/android/internal/util/TestUtils.java b/tests/net/util/java/com/android/internal/util/TestUtils.java
deleted file mode 100644
index daa00d2..0000000
--- a/tests/net/util/java/com/android/internal/util/TestUtils.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-public final class TestUtils {
- private TestUtils() { }
-
- /**
- * Return a new instance of {@code T} after being parceled then unparceled.
- */
- public static <T extends Parcelable> T parcelingRoundTrip(T source) {
- final Parcelable.Creator<T> creator;
- try {
- creator = (Parcelable.Creator<T>) source.getClass().getField("CREATOR").get(null);
- } catch (IllegalAccessException | NoSuchFieldException e) {
- fail("Missing CREATOR field: " + e.getMessage());
- return null;
- }
- Parcel p = Parcel.obtain();
- source.writeToParcel(p, /* flags */ 0);
- p.setDataPosition(0);
- final byte[] marshalled = p.marshall();
- p = Parcel.obtain();
- p.unmarshall(marshalled, 0, marshalled.length);
- p.setDataPosition(0);
- return creator.createFromParcel(p);
- }
-
- /**
- * Assert that after being parceled then unparceled, {@code source} is equal to the original
- * object.
- */
- public static <T extends Parcelable> void assertParcelingIsLossless(T source) {
- assertEquals(source, parcelingRoundTrip(source));
- }
-}