Java Code Examples for rx.observers.TestSubscriber#unsubscribe()
The following examples show how to use
rx.observers.TestSubscriber#unsubscribe() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxFirebaseStorageTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void putBytes() { TestSubscriber<UploadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>(); RxFirebaseStorage.putBytes(mockStorageRef, bytes) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(uploadSnapshot); verify(mockStorageRef).putBytes(bytes); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(uploadSnapshot)); testSubscriber.assertNotCompleted(); testSubscriber.unsubscribe(); }
Example 2
Source File: RxFirebaseDatabaseTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void testObserveChildEvent_Added() { 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(); }
Example 3
Source File: RxFirebaseUserTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void linkWithCredential() { TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>(); RxFirebaseUser.linkWithCredential(mockUser, credential) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(authResult); testOnCompleteListener.getValue().onComplete(mockAuthResultTask); verify(mockUser).linkWithCredential(credential); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(authResult)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example 4
Source File: RxTiPresenterSubscriptionHandlerTest.java From ThirtyInch with Apache License 2.0 | 6 votes |
@Test public void testManageSubscriptions_WithAlreadyUnsubscribedSubscription_ShouldDoNothing() throws Exception { TestSubscriber<Void> firstSubscriber = new TestSubscriber<>(); TestSubscriber<Void> secondSubscriber = new TestSubscriber<>(); TestSubscriber<Void> thirdSubscriber = new TestSubscriber<>(); firstSubscriber.unsubscribe(); secondSubscriber.unsubscribe(); thirdSubscriber.unsubscribe(); mSubscriptionHandler.manageSubscriptions(firstSubscriber, secondSubscriber, thirdSubscriber); firstSubscriber.assertUnsubscribed(); secondSubscriber.assertUnsubscribed(); thirdSubscriber.assertUnsubscribed(); }
Example 5
Source File: RxFirebaseDatabaseTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void testObserveSingleValue() { TestSubscriber<TestData> testSubscriber = new TestSubscriber<>(); RxFirebaseDatabase.observeSingleValueEvent(mockDatabase, TestData.class) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); ArgumentCaptor<ValueEventListener> argument = ArgumentCaptor.forClass(ValueEventListener.class); verify(mockDatabase).addListenerForSingleValueEvent(argument.capture()); argument.getValue().onDataChange(mockFirebaseDataSnapshot); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(testData)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example 6
Source File: RxFirebaseStorageTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void putStream() { TestSubscriber<UploadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>(); RxFirebaseStorage.putStream(mockStorageRef, stream) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(uploadSnapshot); verify(mockStorageRef).putStream(stream); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(uploadSnapshot)); testSubscriber.assertNotCompleted(); testSubscriber.unsubscribe(); }
Example 7
Source File: RxFirebaseDatabaseTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void testObserveValueEvent() { TestSubscriber<TestData> testSubscriber = new TestSubscriber<>(); RxFirebaseDatabase.observeValueEvent(mockDatabase, TestData.class) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); ArgumentCaptor<ValueEventListener> argument = ArgumentCaptor.forClass(ValueEventListener.class); verify(mockDatabase).addValueEventListener(argument.capture()); argument.getValue().onDataChange(mockFirebaseDataSnapshot); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(testData)); testSubscriber.assertNotCompleted(); testSubscriber.unsubscribe(); }
Example 8
Source File: RxFirebaseStorageTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void putFileMetadata() { TestSubscriber<UploadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>(); RxFirebaseStorage.putFile(mockStorageRef, uri, metadata) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(uploadSnapshot); verify(mockStorageRef).putFile(uri, metadata); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(uploadSnapshot)); testSubscriber.assertNotCompleted(); testSubscriber.unsubscribe(); }
Example 9
Source File: RxFirebaseConfigTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void fetch() { TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); RxFirebaseConfig.fetch(mockConfig) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(mockRes); testOnCompleteListener.getValue().onComplete(mockTask); verify(mockConfig).fetch(); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(mockRes)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example 10
Source File: RxFirebaseAuthTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void signInWithEmailAndPassword_AuthError() { TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>(); RxFirebaseAuth.signInWithEmailAndPassword(mockAuth, "email", "password") .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); Exception e = new Exception("something bad happened"); testOnFailureListener.getValue().onFailure(e); verify(mockAuth).signInWithEmailAndPassword(eq("email"), eq("password")); testSubscriber.assertError(e); testSubscriber.assertNotCompleted(); testSubscriber.unsubscribe(); }
Example 11
Source File: RxFirebaseAuthTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void signInAnonymously() { TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>(); RxFirebaseAuth.signInAnonymously(mockAuth) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(mockAuthResult); testOnCompleteListener.getValue().onComplete(mockAuthTask); verify(mockAuth).signInAnonymously(); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(mockAuthResult)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example 12
Source File: RxFirebaseStorageTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void getStream() { TestSubscriber<StreamDownloadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>(); RxFirebaseStorage.getStream(mockStorageRef) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(streamSnapshot); verify(mockStorageRef).getStream(); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(streamSnapshot)); testSubscriber.assertNotCompleted(); testSubscriber.unsubscribe(); }
Example 13
Source File: RxFirebaseUserTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void updatePassword() { TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); RxFirebaseUser.updatePassword(mockUser, "password") .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(mockRes); testOnCompleteListener.getValue().onComplete(mockTask); verify(mockUser).updatePassword("password"); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(mockRes)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example 14
Source File: RxFirebaseDatabaseTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void testObserveChildEvent_Changed() { 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(); }
Example 15
Source File: RxFirebaseStorageTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void getDownloadUrl() { TestSubscriber<Uri> testSubscriber = new TestSubscriber<>(); RxFirebaseStorage.getDownloadUrl(mockStorageRef) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(uri); testOnCompleteListener.getValue().onComplete(mockUriTask); verify(mockStorageRef).getDownloadUrl(); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(uri)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example 16
Source File: RxFirebaseDatabaseTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void testSingleValueEvent() { TestSubscriber<TestData> testSubscriber = new TestSubscriber<>(); RxFirebaseDatabase.observeSingleValueEvent(mockDatabase, TestData.class) .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); ArgumentCaptor<ValueEventListener> argument = ArgumentCaptor.forClass(ValueEventListener.class); verify(mockDatabase).addListenerForSingleValueEvent(argument.capture()); argument.getValue().onDataChange(mockFirebaseDataSnapshot); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(testData)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example 17
Source File: OperatorBufferToFileTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
@Test public void handlesUnsubscription() throws InterruptedException { System.out.println("handlesUnsubscription"); Scheduler scheduler = createSingleThreadScheduler(); TestSubscriber<String> ts = TestSubscriber.create(0); Observable.just("abc", "def", "ghi") // .compose(Transformers.onBackpressureBufferToFile(DataSerializers.string(), scheduler, Options.defaultInstance())) .subscribe(ts); ts.requestMore(2); TimeUnit.MILLISECONDS.sleep(500); ts.unsubscribe(); TimeUnit.MILLISECONDS.sleep(500); ts.assertValues("abc", "def"); waitUntilWorkCompleted(scheduler); }
Example 18
Source File: RxOkukiTest.java From okuki with Apache License 2.0 | 5 votes |
@Test public void testGlobalSubscription() throws Exception { TestSubscriber<Place> testObserver = TestSubscriber.create(); RxOkuki.onAnyPlace(okuki).subscribe(testObserver); verify(okuki).addGlobalListener(isA(GlobalListener.class)); testObserver.unsubscribe(); verify(okuki).removeGlobalListener(isA(GlobalListener.class)); }
Example 19
Source File: FileObservableTest.java From rxjava-file with Apache License 2.0 | 5 votes |
@Test public void testTailTextFileStreamsFromEndOfFileIfSpecified() throws FileNotFoundException, InterruptedException { File file = new File("target/test1.txt"); file.delete(); try (PrintStream out = new PrintStream(file)) { out.println("line 1"); } final List<String> list = new ArrayList<String>(); TestSubscriber<String> ts = TestSubscriber.create(); FileObservable.tailer().file(file).startPosition(file.length()).sampleTimeMs(10).utf8() .tailText() // for each .doOnNext(new Action1<String>() { @Override public void call(String line) { System.out.println(line); list.add(line); } }).subscribeOn(Schedulers.newThread()).subscribe(ts); Thread.sleep(1100); assertTrue(list.isEmpty()); try (PrintStream out = new PrintStream(new FileOutputStream(file, true))) { out.println("line 2"); } Thread.sleep(1100); assertEquals(1, list.size()); assertEquals("line 2", list.get(0).trim()); ts.unsubscribe(); }
Example 20
Source File: OperatorBufferToFileTest.java From rxjava-extras with Apache License 2.0 | 5 votes |
@Test public void handlesUnsubscriptionDuringDrainLoop() throws InterruptedException { System.out.println("handlesUnsubscriptionDuringDrainLoop"); Scheduler scheduler = createSingleThreadScheduler(); TestSubscriber<String> ts = TestSubscriber.create(0); Observable.just("abc", "def", "ghi") // .compose(Transformers.onBackpressureBufferToFile(DataSerializers.string(), scheduler)) .doOnNext(new Action1<Object>() { @Override public void call(Object t) { try { // pauses drain loop Thread.sleep(500); } catch (InterruptedException e) { } } }).subscribe(ts); ts.requestMore(2); TimeUnit.MILLISECONDS.sleep(250); ts.unsubscribe(); TimeUnit.MILLISECONDS.sleep(500); ts.assertValues("abc"); waitUntilWorkCompleted(scheduler); }