PermissionDataProvider implements PermissionActionProvider { @Override public Single<Boolean> isGranted(Permission permission) { PermissionEntity permissionEntity = permissionEntityDataMapper.transformInverse(permission); return Single.just(permissionChecker.checkSelfPermission(context, permissionEntity)) .map(permissionChecker::isGranted); } @Inject  PermissionDataProvider(AndroidPermissionChecker androidPermissionChecker,
      PermissionEntityDataMapper permissionEntityDataMapper); @Override Single<Boolean> isGranted(Permission permission); @Override Single<Boolean> request(Permission permission);  }
@Test public void shouldNotifyPermissionIsGrantedWhenItsActuallyGranted() throws Exception { Permission permission = getPermission(); PermissionEntity permissionEntity = getPermissionEntity(); when(mockPermissionEntityDataMapper.transformInverse(permission)).thenReturn(permissionEntity); when(mockAndroidPermissionChecker.checkSelfPermission(any(Context.class), same(permissionEntity))).thenReturn(0); when(mockAndroidPermissionChecker.isGranted(0)).thenReturn(true); Single<Boolean> isGranted = permissionActionProvider.isGranted(permission); assertThat(isGranted).isNotNull(); TestObserver<Boolean> testObserver = isGranted.test(); testObserver.assertNoErrors(); List<Boolean> streamValues = testObserver.values(); assertThat(streamValues).isNotNull(); assertThat(streamValues.size()).isEqualTo(1); assertThat(streamValues.get(0)).isTrue(); }
@Test public void shouldNotifyPermissionNotGrantedWhenItsActuallyNotGranted() throws Exception { Permission permission = getPermission(); PermissionEntity permissionEntity = getPermissionEntity(); when(mockPermissionEntityDataMapper.transformInverse(permission)).thenReturn(permissionEntity); when(mockAndroidPermissionChecker.checkSelfPermission(any(Context.class), same(permissionEntity))).thenReturn(-1); when(mockAndroidPermissionChecker.isGranted(-1)).thenReturn(false); Single<Boolean> isGranted = permissionActionProvider.isGranted(permission); assertThat(isGranted).isNotNull(); TestObserver<Boolean> testObserver = isGranted.test(); testObserver.assertNoErrors(); List<Boolean> streamValues = testObserver.values(); assertThat(streamValues).isNotNull(); assertThat(streamValues.size()).isEqualTo(1); assertThat(streamValues.get(0)).isFalse(); }