diff options
author | Maciej Żenczykowski <maze@google.com> | 2021-03-16 06:42:28 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-03-16 06:42:28 +0000 |
commit | 9a575c69944a90549074e1e3fb222fd98ef67297 (patch) | |
tree | 4d640f7c5fdaa3659131e67070c9951e8f8a4b5a /common | |
parent | 52a53ee5141c28893bc5cee997a77b04940dca9f (diff) | |
parent | ac2b1112cf3dffe019cedaeeeaab204a51a355ae (diff) | |
download | net-9a575c69944a90549074e1e3fb222fd98ef67297.tar.gz |
Merge "Fix LocationPermissionCheckerTest"
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 { |