diff options
author | Remi NGUYEN VAN <reminv@google.com> | 2021-03-16 13:29:31 +0900 |
---|---|---|
committer | Remi NGUYEN VAN <reminv@google.com> | 2021-03-16 13:31:10 +0900 |
commit | ac2b1112cf3dffe019cedaeeeaab204a51a355ae (patch) | |
tree | 477fdc87a69a60d1acd35420426a58cdedd98f99 /common | |
parent | ecb948964f8603d1b580cb49e087fb5b4831a435 (diff) | |
download | net-ac2b1112cf3dffe019cedaeeeaab204a51a355ae.tar.gz |
Fix LocationPermissionCheckerTest
The mocking of services was incorrect for services queried by class name
instead of service name.
Fix getSystemService mocking to cover both methods.
Bug: 181837977
Test: atest NetworkStaticLibTests
Change-Id: Ifc9bc26e85b5152754941bbe33bccdefff62195a
Diffstat (limited to 'common')
-rw-r--r-- | common/tests/unit/src/com/android/net/module/util/LocationPermissionCheckerTest.java | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/common/tests/unit/src/com/android/net/module/util/LocationPermissionCheckerTest.java b/common/tests/unit/src/com/android/net/module/util/LocationPermissionCheckerTest.java index 78a21a6c..3fb1e929 100644 --- a/common/tests/unit/src/com/android/net/module/util/LocationPermissionCheckerTest.java +++ b/common/tests/unit/src/com/android/net/module/util/LocationPermissionCheckerTest.java @@ -119,11 +119,16 @@ public class LocationPermissionCheckerTest { + " to application bound to user " + mUid)) .when(mMockAppOps).checkPackage(mUid, TEST_PKG_NAME); } - when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)) - .thenReturn(mMockAppOps); - when(mMockContext.getSystemService(Context.USER_SERVICE)) - .thenReturn(mMockUserManager); - when(mMockContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager); + mockSystemService(Context.APP_OPS_SERVICE, AppOpsManager.class, mMockAppOps); + mockSystemService(Context.USER_SERVICE, UserManager.class, mMockUserManager); + mockSystemService(Context.LOCATION_SERVICE, LocationManager.class, mLocationManager); + } + + private <T> void mockSystemService(String name, Class<T> clazz, T service) { + when(mMockContext.getSystemService(name)).thenReturn(service); + when(mMockContext.getSystemServiceName(clazz)).thenReturn(name); + // Do not use mockito extended final method mocking + when(mMockContext.getSystemService(clazz)).thenCallRealMethod(); } private void setupTestCase() throws Exception { |