EasyPermissions { public static boolean hasPermissions(@NonNull Context context, @Size(min = 1) @NonNull String... perms) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { Log.w(TAG, "hasPermissions: API version < M, returning true by default"); return true; } if (context == null) { throw new IllegalArgumentException("Can't check permissions for null context"); } for (String perm : perms) { if (ContextCompat.checkSelfPermission(context, perm) != PackageManager.PERMISSION_GRANTED) { return false; } } return true; }  static boolean hasPermissions(@NonNull Context context,
                                         @Size(min = 1) @NonNull String... perms); static void requestPermissions(
            @NonNull Activity host, @NonNull String rationale,
            int requestCode, @Size(min = 1) @NonNull String... perms); static void requestPermissions(
            @NonNull Fragment host, @NonNull String rationale,
            int requestCode, @Size(min = 1) @NonNull String... perms); static void requestPermissions(PermissionRequest request); static void onRequestPermissionsResult(int requestCode,
                                                  @NonNull String[] permissions,
                                                  @NonNull int[] grantResults,
                                                  @NonNull Object... receivers); static boolean somePermissionPermanentlyDenied(@NonNull Activity host,
                                                          @NonNull List<String> deniedPermissions); static boolean somePermissionPermanentlyDenied(@NonNull Fragment host,
                                                          @NonNull List<String> deniedPermissions); static boolean permissionPermanentlyDenied(@NonNull Activity host,
                                                      @NonNull String deniedPermission); static boolean permissionPermanentlyDenied(@NonNull Fragment host,
                                                      @NonNull String deniedPermission); static boolean somePermissionDenied(@NonNull Activity host,
                                               @NonNull String... perms); static boolean somePermissionDenied(@NonNull Fragment host,
                                               @NonNull String... perms);  }
@Test public void shouldNotHavePermissions_whenNoPermissionsGranted() { assertThat(EasyPermissions.hasPermissions(app, ALL_PERMS)).isFalse(); }
@Test public void shouldNotHavePermissions_whenNotAllPermissionsGranted() { shadowApp.grantPermissions(ONE_PERM); assertThat(EasyPermissions.hasPermissions(app, ALL_PERMS)).isFalse(); }
@Test public void shouldHavePermissions_whenAllPermissionsGranted() { shadowApp.grantPermissions(ALL_PERMS); assertThat(EasyPermissions.hasPermissions(app, ALL_PERMS)).isTrue(); }
@SuppressWarnings("ConstantConditions") @Test public void shouldThrowException_whenHasPermissionsWithNullContext() { try { EasyPermissions.hasPermissions(null, ALL_PERMS); fail("IllegalStateException expected because of null context."); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat() .isEqualTo("Can't check permissions for null context"); } }