本文整理汇总了Java中com.google.firebase.database.ChildEventListener类的典型用法代码示例。如果您正苦于以下问题:Java ChildEventListener类的具体用法?Java ChildEventListener怎么用?Java ChildEventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChildEventListener类属于com.google.firebase.database包,在下文中一共展示了ChildEventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testObserveChildEvent_Added
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEvent_Added() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
.subscribeOn(Schedulers.immediate())
.subscribe(testSubscriber);
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(mockDatabase).addChildEventListener(argument.capture());
argument.getValue().onChildAdded(mockFirebaseDataSnapshot, "root");
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventAdded));
testSubscriber.assertNotCompleted();
testSubscriber.unsubscribe();
}
示例2: testObserveChildEvent_Changed
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEvent_Changed() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
.subscribeOn(Schedulers.immediate())
.subscribe(testSubscriber);
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(mockDatabase).addChildEventListener(argument.capture());
argument.getValue().onChildChanged(mockFirebaseDataSnapshot, "root");
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventChanged));
testSubscriber.assertNotCompleted();
testSubscriber.unsubscribe();
}
示例3: testObserveChildEvent_Removed
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEvent_Removed() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
.subscribeOn(Schedulers.immediate())
.subscribe(testSubscriber);
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(mockDatabase).addChildEventListener(argument.capture());
argument.getValue().onChildRemoved(mockFirebaseDataSnapshot);
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventRemoved));
testSubscriber.assertNotCompleted();
testSubscriber.unsubscribe();
}
示例4: testObserveChildEvent_Moved
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEvent_Moved() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
.subscribeOn(Schedulers.immediate())
.subscribe(testSubscriber);
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(mockDatabase).addChildEventListener(argument.capture());
argument.getValue().onChildMoved(mockFirebaseDataSnapshot, "root");
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventMoved));
testSubscriber.assertNotCompleted();
testSubscriber.unsubscribe();
}
示例5: testObserveChildEvent_Cancelled
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEvent_Cancelled() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
.subscribeOn(Schedulers.immediate())
.subscribe(testSubscriber);
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(mockDatabase).addChildEventListener(argument.capture());
argument.getValue().onCancelled(DatabaseError.zzqv(DatabaseError.DISCONNECTED));
testSubscriber.assertError(RxFirebaseDataException.class);
testSubscriber.assertNotCompleted();
testSubscriber.unsubscribe();
}
示例6: registerFeedChangedEvent
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Override
public Observable<FeedChangedInfoEntity> registerFeedChangedEvent() {
return Observable.fromAsync(new Action1<AsyncEmitter<FeedChangedInfoEntity>>() {
@Override
public void call(AsyncEmitter<FeedChangedInfoEntity> feedChangedInfoEntityAsyncEmitter) {
Timber.v(String.format("fromAsync create : %s", Thread.currentThread().getName()));
// those of registered method will be called in a background thread
final Query query = database.child(Firebase.QUERY_FEEDS);
final ChildEventListener listener = new FeedChangeListener(feedChangedInfoEntityAsyncEmitter);
query.addChildEventListener(listener);
feedChangedInfoEntityAsyncEmitter.setCancellation(new AsyncEmitter.Cancellable() {
@Override
public void cancel() throws Exception {
database.removeEventListener(listener);
}
});
}
}, AsyncEmitter.BackpressureMode.BUFFER);
}
示例7: shouldBufferChildEvents
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void shouldBufferChildEvents() throws Exception {
ArgumentCaptor<ChildEventListener> captor = forClass(ChildEventListener.class);
TestSubscriber<ChildEvent> subscriber = rx.onChildEvent().test(1);
then(query).should().addChildEventListener(captor.capture());
ChildEventListener listener = captor.getValue();
DataSnapshot snapshot = mock(DataSnapshot.class);
listener.onChildAdded(snapshot, null);
listener.onChildAdded(snapshot, null);
subscriber
.assertValueCount(1)
.assertNoErrors();
}
示例8: shouldFilterChildEvent
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void shouldFilterChildEvent() throws Exception {
ArgumentCaptor<ChildEventListener> captor = forClass(ChildEventListener.class);
TestSubscriber<ChildEvent> subscriber = rx.onChildEvent(ChildEvent.Type.CHILD_ADDED).test();
then(query).should().addChildEventListener(captor.capture());
ChildEventListener listener = captor.getValue();
DataSnapshot snapshot = mock(DataSnapshot.class);
listener.onChildAdded(snapshot, null);
listener.onChildChanged(snapshot, null);
subscriber
.assertValueCount(1)
.assertNoErrors();
}
示例9: shouldParseChildEventValue
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void shouldParseChildEventValue() throws Exception {
ArgumentCaptor<ChildEventListener> captor = forClass(ChildEventListener.class);
TestSubscriber<String> subscriber = rx
.onChildEventValue(ChildEvent.Type.CHILD_ADDED, String.class)
.test();
then(query).should().addChildEventListener(captor.capture());
ChildEventListener listener = captor.getValue();
DataSnapshot snapshot = mock(DataSnapshot.class);
given(snapshot.getValue(String.class)).willReturn("biscuits");
listener.onChildAdded(snapshot, null);
subscriber
.assertValue("biscuits")
.assertNoErrors();
}
示例10: testObserveChildEventAdded
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEventAdded() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
.observeChildEvent(databaseReference, ChildData.class)
.test();
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(databaseReference).addChildEventListener(argument.capture());
argument.getValue().onChildAdded(dataSnapshot, PREVIOUS_CHILD_NAME);
testObserver.assertNoErrors()
.assertValueCount(1)
.assertValueSet(Collections.singletonList(childEventAdded))
.assertNotComplete()
.dispose();
}
示例11: testObserveChildEventChanged
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEventChanged() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
.observeChildEvent(databaseReference, ChildData.class)
.test();
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(databaseReference).addChildEventListener(argument.capture());
argument.getValue().onChildChanged(dataSnapshot, PREVIOUS_CHILD_NAME);
testObserver.assertNoErrors()
.assertValueCount(1)
.assertValueSet(Collections.singletonList(childEventChanged))
.assertNotComplete()
.dispose();
}
示例12: testObserveChildEventRemoved
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEventRemoved() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
.observeChildEvent(databaseReference, ChildData.class)
.test();
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(databaseReference).addChildEventListener(argument.capture());
argument.getValue().onChildRemoved(dataSnapshot);
testObserver.assertNoErrors()
.assertValueCount(1)
.assertValueSet(Collections.singletonList(childEventRemoved))
.assertNotComplete()
.dispose();
}
示例13: testObserveChildEventMoved
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testObserveChildEventMoved() throws InterruptedException {
TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
.observeChildEvent(databaseReference, ChildData.class)
.test();
ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
verify(databaseReference).addChildEventListener(argument.capture());
argument.getValue().onChildMoved(dataSnapshot, PREVIOUS_CHILD_NAME);
testObserver.assertNoErrors()
.assertValueCount(1)
.assertValueSet(Collections.singletonList(childEventMoved))
.assertNotComplete()
.dispose();
}
示例14: testChildAddedEvents
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
@Test
public void testChildAddedEvents() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;
Map<String, Object> initial =
new MapBuilder()
.put("a", MapBuilder.of("value", 5L))
.put("c", MapBuilder.of("value", 3L))
.build();
final List<String> snapshotNames = new ArrayList<>();
final List<String> prevNames = new ArrayList<>();
final Semaphore semaphore = new Semaphore(0);
final ChildEventListener testListener =
ref.orderByChild("value")
.addChildEventListener(
new TestChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snap, String prevName) {
snapshotNames.add(snap.getKey());
prevNames.add(prevName);
semaphore.release();
}
});
ref.setValueAsync(initial);
TestHelpers.waitFor(semaphore, 2);
Assert.assertEquals(Arrays.asList("c", "a"), snapshotNames);
Assert.assertEquals(Arrays.asList(null, "c"), prevNames);
Map<String, Object> updates = new HashMap<>();
updates.put("b", MapBuilder.of("value", 4));
updates.put("d", MapBuilder.of("value", 2));
ref.updateChildrenAsync(updates);
TestHelpers.waitFor(semaphore, 2);
Assert.assertEquals(Arrays.asList("c", "a", "d", "b"), snapshotNames);
Assert.assertEquals(Arrays.asList(null, "c", null, "c"), prevNames);
ref.removeEventListener(testListener);
}
示例15: breakCombo
import com.google.firebase.database.ChildEventListener; //导入依赖的package包/类
/** Remove the saved listener from the saved ref.*/
public void breakCombo(){
DatabaseReference comboRef = FirebaseDatabase.getInstance().getReferenceFromUrl(ref);
listener.killEvent();
if (listener.getType() == FirebaseGeneralEvent.ChildEvent)
{
comboRef.removeEventListener((ChildEventListener) listener);
}
else if (listener.getType() == FirebaseGeneralEvent.ValueEvent)
{
comboRef.removeEventListener((ValueEventListener) listener);
}
}