RxFirebaseDatabase { @NonNull @CheckReturnValue public static <T> Observable<DataValue<T>> dataChangesOf( @NonNull final DatabaseReference ref, @NonNull final Class<T> clazz) { return dataChanges(ref).compose(new TransformerOfClazz<>(clazz)); } private  RxFirebaseDatabase(); @NonNull @CheckReturnValue static Observable<ChildEvent> childEvents(@NonNull final Query query); @NonNull @CheckReturnValue static Single<DataSnapshot> data(@NonNull final Query query); @NonNull @CheckReturnValue static Observable<DataSnapshot> dataChanges(@NonNull final Query query); @NonNull @CheckReturnValue static Observable<DataValue<T>> dataChangesOf(
            @NonNull final DatabaseReference ref, @NonNull final Class<T> clazz); @NonNull @CheckReturnValue static Observable<DataValue<T>> dataChangesOf(
            @NonNull final Query query, @NonNull final Class<T> clazz); @NonNull @CheckReturnValue static Observable<DataValue<T>> dataChangesOf(
            @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator); @NonNull @CheckReturnValue static Observable<DataValue<T>> dataChangesOf(
            @NonNull Query query, @NonNull GenericTypeIndicator<T> typeIndicator); @NonNull @CheckReturnValue static Single<T> dataOf(
            @NonNull DatabaseReference ref, @NonNull Class<T> clazz); @NonNull @CheckReturnValue static Single<T> dataOf(
            @NonNull Query query, @NonNull Class<T> clazz); @NonNull @CheckReturnValue static Single<T> dataOf(
            @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator); @NonNull @CheckReturnValue static Single<T> dataOf(
            @NonNull Query query, @NonNull GenericTypeIndicator<T> typeIndicator); @NonNull @CheckReturnValue static Completable removeValue(@NonNull final DatabaseReference ref); @NonNull @CheckReturnValue static Completable setPriority(
            @NonNull final DatabaseReference ref, @NonNull final Object priority); @NonNull @CheckReturnValue static Completable setValue(
            @NonNull final DatabaseReference ref,
            @NonNull final T value); @NonNull @CheckReturnValue static Completable setValue(
            @NonNull final DatabaseReference ref,
            @NonNull final T value,
            @NonNull final Object priority); @NonNull @CheckReturnValue static Single<DataSnapshot> runTransaction(
            @NonNull final DatabaseReference ref,
            @NonNull final Function<MutableData, Transaction.Result> function); @NonNull @CheckReturnValue static Single<DataSnapshot> runTransaction(
            @NonNull final DatabaseReference ref,
            @NonNull final Function<MutableData, Transaction.Result> function,
            final boolean fireLocalEvents); @NonNull @CheckReturnValue static Completable updateChildren(
            @NonNull final DatabaseReference ref, @NonNull final Map<String, Object> map);  }
@Test public void testDataChangesOfClazz_DataReference() { TestObserver<DataValue<String>> sub = TestObserver.create(); RxFirebaseDatabase.dataChangesOf(mockDatabaseReference, String.class) .subscribe(sub); verifyDataReferenceAddValueEventListener(); callValueEventOnDataChange("Foo"); sub.assertNotComplete(); sub.assertValue(new Predicate<DataValue<String>>() { @Override public boolean test(DataValue<String> value) throws Exception { return value.isPresent() && "Foo".equals(value.get()); } }); sub.dispose(); callValueEventOnDataChange("Foo"); sub.assertValueCount(1); }
@Test public void testDataChangesOfGenericTypeIndicator_DataReference() { List<String> values = new ArrayList<>(); values.add("Foo"); values.add("Bar"); GenericTypeIndicator<List<String>> typeIndicator = new GenericTypeIndicator<List<String>>() { }; TestObserver<DataValue<List<String>>> sub = TestObserver.create(); RxFirebaseDatabase.dataChangesOf(mockDatabaseReference, typeIndicator) .subscribe(sub); verifyDataReferenceAddValueEventListener(); callValueEventOnDataChange(typeIndicator, values); sub.assertNotComplete(); sub.assertValue(new Predicate<DataValue<List<String>>>() { @Override public boolean test(DataValue<List<String>> value) throws Exception { return value.isPresent() && "Foo".equals(value.get().get(0)) && "Bar".equals(value.get().get(1)); } }); sub.dispose(); callValueEventOnDataChange(typeIndicator, values); sub.assertValueCount(1); }
@Test public void testDataChangesOfClazz_Query() { TestObserver<DataValue<String>> sub = TestObserver.create(); RxFirebaseDatabase.dataChangesOf(mockQuery, String.class) .subscribe(sub); verifyQueryAddValueEventListener(); callValueEventOnDataChange("Foo"); sub.assertNotComplete(); sub.assertValue(new Predicate<DataValue<String>>() { @Override public boolean test(DataValue<String> value) throws Exception { return value.isPresent() && "Foo".equals(value.get()); } }); sub.dispose(); callValueEventOnDataChange("Foo"); sub.assertValueCount(1); }
@Test public void testDataChangesOfGenericTypeIndicator_Query() { List<String> values = new ArrayList<>(); values.add("Foo"); values.add("Bar"); GenericTypeIndicator<List<String>> typeIndicator = new GenericTypeIndicator<List<String>>() { }; TestObserver<DataValue<List<String>>> sub = TestObserver.create(); RxFirebaseDatabase.dataChangesOf(mockQuery, typeIndicator) .subscribe(sub); verifyQueryAddValueEventListener(); callValueEventOnDataChange(typeIndicator, values); sub.assertNotComplete(); sub.assertValue(new Predicate<DataValue<List<String>>>() { @Override public boolean test(DataValue<List<String>> value) throws Exception { return value.isPresent() && "Foo".equals(value.get().get(0)) && "Bar".equals(value.get().get(1)); } }); sub.dispose(); callValueEventOnDataChange(typeIndicator, values); sub.assertValueCount(1); }