Fix a flake with mocking.

The hypothesis here is that some other thread is using
the mock between the call to when() and the call to
.thenReturn() a few lines above the failure. It's not
clear this is really the reason, but using this syntax
is safer anyway, so whether it fixes the issue or not
this is a good change.

Test: m FrameworksNetTests
Change-Id: I501d2ec8e794c67a53d7c84e290e4cc63481472d
This commit is contained in:
Chalard Jean
2021-07-12 15:25:10 +09:00
parent 5b37955322
commit 6519c179bd

View File

@@ -1529,7 +1529,7 @@ public class ConnectivityServiceTest {
}
private <T> T doAsUid(final int uid, @NonNull final Supplier<T> what) {
when(mDeps.getCallingUid()).thenReturn(uid);
doReturn(uid).when(mDeps).getCallingUid();
try {
return what.get();
} finally {
@@ -9860,9 +9860,9 @@ public class ConnectivityServiceTest {
assertVpnUidRangesUpdated(true, vpnRange, vpnOwnerUid);
final UnderlyingNetworkInfo underlyingNetworkInfo =
new UnderlyingNetworkInfo(vpnOwnerUid, VPN_IFNAME, new ArrayList<String>());
new UnderlyingNetworkInfo(vpnOwnerUid, VPN_IFNAME, new ArrayList<>());
mMockVpn.setUnderlyingNetworkInfo(underlyingNetworkInfo);
when(mDeps.getConnectionOwnerUid(anyInt(), any(), any())).thenReturn(42);
doReturn(42).when(mDeps).getConnectionOwnerUid(anyInt(), any(), any());
}
private void setupConnectionOwnerUidAsVpnApp(int vpnOwnerUid, @VpnManager.VpnType int vpnType)