PermissionManager { public boolean haveAllPermissions() { if (mAndroidLevel < Build.VERSION_CODES.M) { return true; } for (String perm : mPerms) { if (mActivity.checkSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) { return false; } } return true; } PermissionManager(int androidLevel, Activity activity, int requestCode, String[] perms);  PermissionManager(Activity activity, int requestCode, String[] perms); boolean haveAllPermissions(); synchronized void obtainPermission(); synchronized boolean granted(
            int requestCode, String[] permissions, int[] results);  }
@Test public void simpleHaveAllPermissions() { mManager = new PermissionManager( Build.VERSION_CODES.M, mActivity, REQUEST_CODE, NO_PERMS); assertTrue(mManager.haveAllPermissions()); }
@Test public void preMarshmallowPermissions() { mManager = new PermissionManager( Build.VERSION_CODES.LOLLIPOP, mActivity, REQUEST_CODE, REQUIRED_PERMS); assertTrue(mManager.haveAllPermissions()); }
@Test public void haveAllPermissionsYes() { when(mActivity.checkSelfPermission(PERM0)).thenReturn(PackageManager.PERMISSION_GRANTED); when(mActivity.checkSelfPermission(PERM1)).thenReturn(PackageManager.PERMISSION_GRANTED); assertTrue(mManager.haveAllPermissions()); }
@Test public void haveAllPermissionsNo() { when(mActivity.checkSelfPermission(PERM0)).thenReturn(PackageManager.PERMISSION_GRANTED); when(mActivity.checkSelfPermission(PERM1)).thenReturn(PackageManager.PERMISSION_DENIED); assertFalse(mManager.haveAllPermissions()); }