@Test public void testObserveSingleValueEventFailed() { TestObserver<ChildData> testObserver = RxFirebaseDatabase .observeSingleValueEvent(databaseReference, ChildData.class) .test(); ArgumentCaptor<ValueEventListener> argument = ArgumentCaptor.forClass(ValueEventListener.class); verify(databaseReference).addListenerForSingleValueEvent(argument.capture()); argument.getValue().onCancelled(DatabaseError.fromCode(DatabaseError.OPERATION_FAILED)); testObserver.assertError(RxFirebaseDataException.class) .assertNotComplete() .dispose(); }
@NonNull public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) { return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() { @Override public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception { query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { emitter.onSuccess(dataSnapshot); } else { emitter.onComplete(); } } @Override public void onCancelled(DatabaseError error) { if (!emitter.isDisposed()) emitter.onError(new RxFirebaseDataException(error)); } }); } }); }
RxFirebaseDatabase { @NonNull public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) { return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() { @Override public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception { query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { emitter.onSuccess(dataSnapshot); } else { emitter.onComplete(); } } @Override public void onCancelled(DatabaseError error) { if (!emitter.isDisposed()) emitter.onError(new RxFirebaseDataException(error)); } }); } }); } }
RxFirebaseDatabase { @NonNull public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) { return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() { @Override public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception { query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { emitter.onSuccess(dataSnapshot); } else { emitter.onComplete(); } } @Override public void onCancelled(DatabaseError error) { if (!emitter.isDisposed()) emitter.onError(new RxFirebaseDataException(error)); } }); } }); }  }
RxFirebaseDatabase { @NonNull public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) { return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() { @Override public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception { query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { emitter.onSuccess(dataSnapshot); } else { emitter.onComplete(); } } @Override public void onCancelled(DatabaseError error) { if (!emitter.isDisposed()) emitter.onError(new RxFirebaseDataException(error)); } }); } }); }  @NonNull static Flowable<DataSnapshot> observeValueEvent(@NonNull final Query query,
                                                           @NonNull BackpressureStrategy strategy); @NonNull static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query); @NonNull static Single<DataSnapshot> runTransaction(@NonNull final DatabaseReference ref,
                                                      @NonNull final boolean fireLocalEvents,
                                                      @NonNull final long transactionValue); @NonNull static Completable setValue(@NonNull final DatabaseReference ref,
                                       final Object value); @NonNull static Completable updateChildren(@NonNull final DatabaseReference ref,
                                             @NonNull final Map<String, Object> updateData); @NonNull static Flowable<RxFirebaseChildEvent<DataSnapshot>> observeChildEvent(
        @NonNull final Query query, @NonNull BackpressureStrategy strategy); @NonNull static Flowable<DataSnapshot> observeMultipleSingleValueEvent(@NonNull DatabaseReference... whereRefs); @NonNull static Maybe<DatabaseReference[]> requestFilteredReferenceKeys(@NonNull final DatabaseReference from,
                                                                          @NonNull Query whereRef); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Class<T> clazz,
                                                    @NonNull BackpressureStrategy strategy); @NonNull static Maybe<T> observeSingleValueEvent(@NonNull final Query query,
                                                       @NonNull final Class<T> clazz); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Class<T> clazz,
        @NonNull BackpressureStrategy strategy); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Function<? super DataSnapshot, ? extends T> mapper,
                                                    @NonNull BackpressureStrategy strategy); @NonNull static Maybe<T> observeSingleValueEvent(@NonNull final Query query,
                                                       @NonNull final Function<? super DataSnapshot, ? extends T> mapper); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Function<? super RxFirebaseChildEvent<DataSnapshot>,
        ? extends RxFirebaseChildEvent<T>> mapper, @NonNull BackpressureStrategy strategy); @NonNull static Flowable<DataSnapshot> observeValueEvent(@NonNull final Query query); @NonNull static Flowable<RxFirebaseChildEvent<DataSnapshot>> observeChildEvent(
        @NonNull final Query query); @NonNull static Single<DataSnapshot> runTransaction(@NonNull final DatabaseReference ref,
                                                      @NonNull final long transactionValue); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Class<T> clazz); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Class<T> clazz); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Function<? super DataSnapshot, ? extends T> mapper); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Function<? super RxFirebaseChildEvent<DataSnapshot>,
        ? extends RxFirebaseChildEvent<T>> mapper); }
RxFirebaseDatabase { @NonNull public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) { return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() { @Override public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception { query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { emitter.onSuccess(dataSnapshot); } else { emitter.onComplete(); } } @Override public void onCancelled(DatabaseError error) { if (!emitter.isDisposed()) emitter.onError(new RxFirebaseDataException(error)); } }); } }); }  @NonNull static Flowable<DataSnapshot> observeValueEvent(@NonNull final Query query,
                                                           @NonNull BackpressureStrategy strategy); @NonNull static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query); @NonNull static Single<DataSnapshot> runTransaction(@NonNull final DatabaseReference ref,
                                                      @NonNull final boolean fireLocalEvents,
                                                      @NonNull final long transactionValue); @NonNull static Completable setValue(@NonNull final DatabaseReference ref,
                                       final Object value); @NonNull static Completable updateChildren(@NonNull final DatabaseReference ref,
                                             @NonNull final Map<String, Object> updateData); @NonNull static Flowable<RxFirebaseChildEvent<DataSnapshot>> observeChildEvent(
        @NonNull final Query query, @NonNull BackpressureStrategy strategy); @NonNull static Flowable<DataSnapshot> observeMultipleSingleValueEvent(@NonNull DatabaseReference... whereRefs); @NonNull static Maybe<DatabaseReference[]> requestFilteredReferenceKeys(@NonNull final DatabaseReference from,
                                                                          @NonNull Query whereRef); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Class<T> clazz,
                                                    @NonNull BackpressureStrategy strategy); @NonNull static Maybe<T> observeSingleValueEvent(@NonNull final Query query,
                                                       @NonNull final Class<T> clazz); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Class<T> clazz,
        @NonNull BackpressureStrategy strategy); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Function<? super DataSnapshot, ? extends T> mapper,
                                                    @NonNull BackpressureStrategy strategy); @NonNull static Maybe<T> observeSingleValueEvent(@NonNull final Query query,
                                                       @NonNull final Function<? super DataSnapshot, ? extends T> mapper); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Function<? super RxFirebaseChildEvent<DataSnapshot>,
        ? extends RxFirebaseChildEvent<T>> mapper, @NonNull BackpressureStrategy strategy); @NonNull static Flowable<DataSnapshot> observeValueEvent(@NonNull final Query query); @NonNull static Flowable<RxFirebaseChildEvent<DataSnapshot>> observeChildEvent(
        @NonNull final Query query); @NonNull static Single<DataSnapshot> runTransaction(@NonNull final DatabaseReference ref,
                                                      @NonNull final long transactionValue); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Class<T> clazz); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Class<T> clazz); @NonNull static Flowable<T> observeValueEvent(@NonNull final Query query,
                                                    @NonNull final Function<? super DataSnapshot, ? extends T> mapper); @NonNull static Flowable<RxFirebaseChildEvent<T>> observeChildEvent(
        @NonNull final Query query, @NonNull final Function<? super RxFirebaseChildEvent<DataSnapshot>,
        ? extends RxFirebaseChildEvent<T>> mapper);  }