ActivityPermissionsRequester implements PermissionRequester { @NonNull @Override public Single<PermissionAuthorizationResponse> request(@NonNull String manifestPermission) { Logger.info(this, "Requesting permission: {}", manifestPermission); try { return permissionRequesterFactory.get().request(manifestPermission); } catch (IllegalStateException e) { return Single.error(e); } } @Inject  ActivityPermissionsRequester(@NonNull T activity); @VisibleForTesting  ActivityPermissionsRequester(@NonNull HeadlessFragmentPermissionRequesterFactory permissionRequesterFactory); @NonNull @Override Single<PermissionAuthorizationResponse> request(@NonNull String manifestPermission); @Override void markRequestConsumed(@NonNull String manifestPermission);  }
@Test public void request() throws Exception { final String permission = "permission"; final PermissionAuthorizationResponse response = new PermissionAuthorizationResponse(permission, true); when(permissionRequesterFragment.request(permission)).thenReturn(Single.just(response)); permissionsRequester.request(permission).test() .assertValue(response) .assertComplete() .assertNoErrors(); }
@Test public void requestThrowsIllegalStateException() throws Exception { final String permission = "permission"; when(permissionRequesterFragment.request(permission)).thenThrow(new IllegalStateException()); permissionsRequester.request(permission).test() .assertNoValues() .assertNotComplete() .assertError(IllegalStateException.class); }