RequestPermissionInteractor extends SingleInteractor<Boolean, RequestPermissionInteractor.Params> { @Override protected Single<Boolean> buildReactiveStream(Params params) { if (params == null) { return Single.error(new IllegalArgumentException("Invalid Permission")); } return permissionActionProvider.request(params.permission); } RequestPermissionInteractor(PermissionActionProvider permissionActionProvider,
      ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread);   }
@Test public void shouldReturnErrorGivenNullPermission() throws Exception { Single<Boolean> reactiveStream = requestPermissionInteractor.buildReactiveStream(null); assertThat(reactiveStream).isNotNull(); TestObserver<Boolean> testObserver = reactiveStream.test(); testObserver.assertError(IllegalArgumentException.class); testObserver.assertErrorMessage("Invalid Permission"); testObserver.assertNotComplete(); }
@Test public void shouldConfirmGrantedPermissionWhenUserConfirms() throws Exception { Permission permission = getPermission(); RequestPermissionInteractor.Params params = RequestPermissionInteractor.Params.forPermission(permission); when(mockPermissionActionProvider.request(permission)).thenReturn(Single.just(true)); Single<Boolean> reactiveStream = requestPermissionInteractor.buildReactiveStream(params); assertThat(reactiveStream).isNotNull(); TestObserver<Boolean> testObserver = reactiveStream.test(); testObserver.assertNoErrors(); testObserver.assertValue(true); testObserver.assertComplete(); }
@Test public void shouldNotConfirmPermissionWhenUserDoesNotConfirm() throws Exception { Permission permission = getPermission(); RequestPermissionInteractor.Params params = RequestPermissionInteractor.Params.forPermission(permission); when(mockPermissionActionProvider.request(permission)).thenReturn(Single.just(false)); Single<Boolean> reactiveStream = requestPermissionInteractor.buildReactiveStream(params); assertThat(reactiveStream).isNotNull(); TestObserver<Boolean> testObserver = reactiveStream.test(); testObserver.assertNoErrors(); testObserver.assertValue(false); testObserver.assertComplete(); }