@Test public void testObserveAuthState() { TestObserver<FirebaseAuth> authTestObserver = RxFirebaseAuth .observeAuthState(firebaseAuth) .test(); ArgumentCaptor<FirebaseAuth.AuthStateListener> argument = ArgumentCaptor.forClass(FirebaseAuth.AuthStateListener.class); verify(firebaseAuth).addAuthStateListener(argument.capture()); argument.getValue().onAuthStateChanged(firebaseAuth); authTestObserver.assertNoErrors() .assertValueCount(1) .assertValueSet(Collections.singletonList(firebaseAuth)) .assertNotComplete() .dispose(); }
@NonNull public static Observable<FirebaseAuth> observeAuthState(@NonNull final FirebaseAuth firebaseAuth) { return Observable.create(new ObservableOnSubscribe<FirebaseAuth>() { @Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) throws Exception { final FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { emitter.onNext(firebaseAuth); } }; firebaseAuth.addAuthStateListener(authStateListener); emitter.setCancellable(new Cancellable() { @Override public void cancel() throws Exception { firebaseAuth.removeAuthStateListener(authStateListener); } }); } }); }
RxFirebaseAuth { @NonNull public static Observable<FirebaseAuth> observeAuthState(@NonNull final FirebaseAuth firebaseAuth) { return Observable.create(new ObservableOnSubscribe<FirebaseAuth>() { @Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) throws Exception { final FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { emitter.onNext(firebaseAuth); } }; firebaseAuth.addAuthStateListener(authStateListener); emitter.setCancellable(new Cancellable() { @Override public void cancel() throws Exception { firebaseAuth.removeAuthStateListener(authStateListener); } }); } }); } }
RxFirebaseAuth { @NonNull public static Observable<FirebaseAuth> observeAuthState(@NonNull final FirebaseAuth firebaseAuth) { return Observable.create(new ObservableOnSubscribe<FirebaseAuth>() { @Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) throws Exception { final FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { emitter.onNext(firebaseAuth); } }; firebaseAuth.addAuthStateListener(authStateListener); emitter.setCancellable(new Cancellable() { @Override public void cancel() throws Exception { firebaseAuth.removeAuthStateListener(authStateListener); } }); } }); }  }
RxFirebaseAuth { @NonNull public static Observable<FirebaseAuth> observeAuthState(@NonNull final FirebaseAuth firebaseAuth) { return Observable.create(new ObservableOnSubscribe<FirebaseAuth>() { @Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) throws Exception { final FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { emitter.onNext(firebaseAuth); } }; firebaseAuth.addAuthStateListener(authStateListener); emitter.setCancellable(new Cancellable() { @Override public void cancel() throws Exception { firebaseAuth.removeAuthStateListener(authStateListener); } }); } }); }  @NonNull static Maybe<AuthResult> signInAnonymously(@NonNull final FirebaseAuth firebaseAuth); @NonNull static Maybe<AuthResult> signInWithEmailAndPassword(@NonNull final FirebaseAuth firebaseAuth,
                                                               @NonNull final String email,
                                                               @NonNull final String password); @NonNull static Maybe<AuthResult> signInWithCredential(@NonNull final FirebaseAuth firebaseAuth,
                                                         @NonNull final AuthCredential credential); @NonNull static Maybe<AuthResult> signInWithCustomToken(@NonNull final FirebaseAuth firebaseAuth,
                                                          @NonNull final String token); @NonNull static Maybe<AuthResult> createUserWithEmailAndPassword(@NonNull final FirebaseAuth firebaseAuth,
                                                                   @NonNull final String email,
                                                                   @NonNull final String password); @NonNull static Maybe<SignInMethodQueryResult> fetchSignInMethodsForEmail(@NonNull final FirebaseAuth firebaseAuth,
                                                                            @NonNull final String email); @NonNull static Completable sendPasswordResetEmail(@NonNull final FirebaseAuth firebaseAuth,
                                                     @NonNull final String email); @NonNull static Completable updateCurrentUser(@NonNull final FirebaseAuth firebaseAuth,
                                                     @NonNull final FirebaseUser newUser); @NonNull static Observable<FirebaseAuth> observeAuthState(@NonNull final FirebaseAuth firebaseAuth); @NonNull static Maybe<ActionCodeResult> checkActionCode(@NonNull final FirebaseAuth firebaseAuth,
                                                          @NonNull final String code); @NonNull static Completable confirmPasswordReset(@NonNull final FirebaseAuth firebaseAuth,
                                                   @NonNull final String code,
                                                   @NonNull final String newPassword); @NonNull static Completable applyActionCode(@NonNull final FirebaseAuth firebaseAuth,
                                              @NonNull final String code); @NonNull static Maybe<String> verifyPasswordResetCode(@NonNull final FirebaseAuth firebaseAuth,
                                                        @NonNull final String code); @NonNull static Completable addIdTokenListener(@NonNull final FirebaseAuth firebaseAuth,
                                                 @NonNull final FirebaseAuth.IdTokenListener idTokenListener); @NonNull static Completable removeIdTokenListener(@NonNull final FirebaseAuth firebaseAuth,
                                                    @NonNull final FirebaseAuth.IdTokenListener idTokenListener); }
RxFirebaseAuth { @NonNull public static Observable<FirebaseAuth> observeAuthState(@NonNull final FirebaseAuth firebaseAuth) { return Observable.create(new ObservableOnSubscribe<FirebaseAuth>() { @Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) throws Exception { final FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { emitter.onNext(firebaseAuth); } }; firebaseAuth.addAuthStateListener(authStateListener); emitter.setCancellable(new Cancellable() { @Override public void cancel() throws Exception { firebaseAuth.removeAuthStateListener(authStateListener); } }); } }); }  @NonNull static Maybe<AuthResult> signInAnonymously(@NonNull final FirebaseAuth firebaseAuth); @NonNull static Maybe<AuthResult> signInWithEmailAndPassword(@NonNull final FirebaseAuth firebaseAuth,
                                                               @NonNull final String email,
                                                               @NonNull final String password); @NonNull static Maybe<AuthResult> signInWithCredential(@NonNull final FirebaseAuth firebaseAuth,
                                                         @NonNull final AuthCredential credential); @NonNull static Maybe<AuthResult> signInWithCustomToken(@NonNull final FirebaseAuth firebaseAuth,
                                                          @NonNull final String token); @NonNull static Maybe<AuthResult> createUserWithEmailAndPassword(@NonNull final FirebaseAuth firebaseAuth,
                                                                   @NonNull final String email,
                                                                   @NonNull final String password); @NonNull static Maybe<SignInMethodQueryResult> fetchSignInMethodsForEmail(@NonNull final FirebaseAuth firebaseAuth,
                                                                            @NonNull final String email); @NonNull static Completable sendPasswordResetEmail(@NonNull final FirebaseAuth firebaseAuth,
                                                     @NonNull final String email); @NonNull static Completable updateCurrentUser(@NonNull final FirebaseAuth firebaseAuth,
                                                     @NonNull final FirebaseUser newUser); @NonNull static Observable<FirebaseAuth> observeAuthState(@NonNull final FirebaseAuth firebaseAuth); @NonNull static Maybe<ActionCodeResult> checkActionCode(@NonNull final FirebaseAuth firebaseAuth,
                                                          @NonNull final String code); @NonNull static Completable confirmPasswordReset(@NonNull final FirebaseAuth firebaseAuth,
                                                   @NonNull final String code,
                                                   @NonNull final String newPassword); @NonNull static Completable applyActionCode(@NonNull final FirebaseAuth firebaseAuth,
                                              @NonNull final String code); @NonNull static Maybe<String> verifyPasswordResetCode(@NonNull final FirebaseAuth firebaseAuth,
                                                        @NonNull final String code); @NonNull static Completable addIdTokenListener(@NonNull final FirebaseAuth firebaseAuth,
                                                 @NonNull final FirebaseAuth.IdTokenListener idTokenListener); @NonNull static Completable removeIdTokenListener(@NonNull final FirebaseAuth firebaseAuth,
                                                    @NonNull final FirebaseAuth.IdTokenListener idTokenListener);  }