本文整理匯總了Java中rx.observers.TestSubscriber類的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber類的具體用法?Java TestSubscriber怎麽用?Java TestSubscriber使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TestSubscriber類屬於rx.observers包,在下文中一共展示了TestSubscriber類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: searchMakeUp_200OkResponse_InvokesCorrectApiCalls
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void searchMakeUp_200OkResponse_InvokesCorrectApiCalls() {
// Given
when(makeUpProductRestService.searchMakeUpProducts(anyString(), anyString())).thenReturn
(Observable.just(makeUpList()).toList());
// When
TestSubscriber<List<MakeUp>> subscriber = new TestSubscriber<>();
makeUpRepository.searchMakeUp(BRAND_COVERGIRL, PRODUCT_TYPE_LIPSTICK).subscribe(subscriber);
// Then
subscriber.awaitTerminalEvent();
subscriber.assertNoErrors();
List<List<MakeUp>> onNextEvents = subscriber.getOnNextEvents();
List<MakeUp> makeup = onNextEvents.get(0);
Assert.assertEquals(BRAND_COVERGIRL, makeup.get(0).getBrand());
Assert.assertEquals(PRODUCT_TYPE_LIPSTICK, makeup.get(0).getProductType());
verify(makeUpProductRestService).searchMakeUpProducts(BRAND_COVERGIRL,
PRODUCT_TYPE_LIPSTICK);
}
示例2: testUploadFailedUnhandledException
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void testUploadFailedUnhandledException() throws Exception {
final File file = getFile(TEST_FILE);
final String jobId = "job-id";
final Job job = Job.builder()
.setId(jobId)
.setStatus(Status.createQueued(jobId))
.setMetadata(Collections.emptyMap())
.setFilepath(file.getPath())
.setMimeType("text/plain")
.build();
final UploadService service = mock(UploadService.class);
when(service.upload(anyMap(), any(MultipartBody.Part.class)))
.thenThrow(new RuntimeException(""));
final Uploader uploader = new Uploader(service, Schedulers.io());
final TestSubscriber<Status> ts = TestSubscriber.create();
uploader.upload(job, file).subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertError(RuntimeException.class);
ts.assertNoValues();
}
示例3: testManagerViewSubscriptions_WithDetach_ShouldUnsubcribe
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void testManagerViewSubscriptions_WithDetach_ShouldUnsubcribe() throws Exception {
mPresenter.create();
mPresenter.attachView(mView);
TestSubscriber<Void> firstSubscriber = new TestSubscriber<>();
TestSubscriber<Void> secondSubscriber = new TestSubscriber<>();
TestSubscriber<Void> thirdSubscriber = new TestSubscriber<>();
mSubscriptionHandler
.manageViewSubscriptions(firstSubscriber, secondSubscriber, thirdSubscriber);
assertThat(firstSubscriber.isUnsubscribed(), equalTo(false));
assertThat(secondSubscriber.isUnsubscribed(), equalTo(false));
assertThat(thirdSubscriber.isUnsubscribed(), equalTo(false));
mPresenter.detachView();
firstSubscriber.assertUnsubscribed();
secondSubscriber.assertUnsubscribed();
thirdSubscriber.assertUnsubscribed();
}
示例4: testManageSubscriptions_WithAlreadyUnsubscribedSubscription_ShouldDoNothing
import rx.observers.TestSubscriber; //導入依賴的package包/類
@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();
}
示例5: testManageSubscriptions_WithDestroy_ShouldUnsubscribe
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void testManageSubscriptions_WithDestroy_ShouldUnsubscribe() throws Exception {
mPresenter.create();
TestSubscriber<Void> firstSubscriber = new TestSubscriber<>();
TestSubscriber<Void> secondSubscriber = new TestSubscriber<>();
TestSubscriber<Void> thirdSubscriber = new TestSubscriber<>();
mSubscriptionHandler.manageSubscriptions(firstSubscriber, secondSubscriber, thirdSubscriber);
assertThat(firstSubscriber.isUnsubscribed(), equalTo(false));
assertThat(secondSubscriber.isUnsubscribed(), equalTo(false));
assertThat(thirdSubscriber.isUnsubscribed(), equalTo(false));
mPresenter.destroy();
firstSubscriber.assertUnsubscribed();
secondSubscriber.assertUnsubscribed();
thirdSubscriber.assertUnsubscribed();
}
示例6: testUploadFileNotFound
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void testUploadFileNotFound() throws Exception {
final String jobId = "job-id";
final Job job = Job.builder()
.setId(jobId)
.setFilepath("invalid")
.setMetadata(Collections.emptyMap())
.setMimeType("text/plain")
.setStatus(Status.createQueued(jobId))
.build();
when(dataStore.get(jobId)).thenReturn(Observable.just(job));
final TestSubscriber<Status> ts = TestSubscriber.create();
uploadInteractor.upload(jobId).subscribe(ts);
testScheduler.triggerActions();
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertError(FileNotFoundException.class);
ts.assertNoValues();
verify(uploader, times(0)).upload(any(Job.class), any(File.class));
}
示例7: rxObservableIntFallback
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void rxObservableIntFallback() {
server.enqueue(new MockResponse().setResponseCode(500));
TestInterface api = target();
Observable<Integer> observable = api.intObservable();
assertThat(observable).isNotNull();
assertThat(server.getRequestCount()).isEqualTo(0);
TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
observable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
Assertions.assertThat(testSubscriber.getOnNextEvents().get(0)).isEqualTo(new Integer(0));
}
示例8: testSchedulerProvider
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void testSchedulerProvider() {
SchedulerProvider schedulerProvider = mock(SchedulerProvider.class);
UseCase usecase = new UseCase<Object>(schedulerProvider) {
@Override
public Observable<Object> createObservable() {
return Observable.just(new Object());
}
};
// when executing with subscriber
TestSubscriber<Object> testSubscriber = new TestSubscriber<Object>();
usecase.execute(testSubscriber);
// then should ask provider for shedulers
verify(schedulerProvider).computation();
verify(schedulerProvider).ui();
}
示例9: fetchOnlyOnePackageIfMoreVersionsOfAnAppHaveBeenSaved
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void fetchOnlyOnePackageIfMoreVersionsOfAnAppHaveBeenSaved() {
List<AppInfo> savedPackages = Arrays.asList(facebookInfo, facebookInfoVersion2);
List<PackageInfo> installedPackages = Collections.emptyList();
when(appProvider.getInstalledPackages()).thenReturn(Observable.just(installedPackages));
when(appService.allInfos()).thenReturn(Observable.just(savedPackages));
TestSubscriber<List<String>> subscriber = new TestSubscriber<>();
fetchOutdatedPackages.get().toBlocking().subscribe(subscriber);
List<String> expectedPackages = Collections.singletonList(facebookInfo.packageName());
List<String> receivedPackages = subscriber.getOnNextEvents().get(0);
Assertions.assertThat(receivedPackages).containsAll(expectedPackages);
subscriber.assertCompleted();
}
示例10: rxCompletableEmptyBody
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void rxCompletableEmptyBody() {
server.enqueue(new MockResponse());
TestInterface api = target();
Completable completable = api.completable();
assertThat(completable).isNotNull();
assertThat(server.getRequestCount()).isEqualTo(0);
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
completable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertCompleted();
testSubscriber.assertNoErrors();
}
示例11: testUploadFileNotFoundException
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void testUploadFileNotFoundException() throws Exception {
final File file = new File("invalid");
final String jobId = "job-id";
final Job job = Job.builder()
.setId(jobId)
.setStatus(Status.createQueued(jobId))
.setMetadata(Collections.emptyMap())
.setFilepath("invalid")
.setMimeType("text/plain")
.build();
final UploadService service = mock(UploadService.class);
final Uploader uploader = new Uploader(service, Schedulers.io());
final TestSubscriber<Status> ts = TestSubscriber.create();
uploader.upload(job, file).subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertError(FileNotFoundException.class);
ts.assertNoValues();
}
示例12: fetchAllAppsFromDeviceIfNoneAreSavedInDB
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void fetchAllAppsFromDeviceIfNoneAreSavedInDB() {
List<PackageInfo> installedPackages =
Arrays.asList(MockPackageInfo.TEST, MockPackageInfo.TEST2);
when(appProvider.getInstalledPackages()).thenReturn(Observable.just(installedPackages));
when(appService.allInfos()).thenReturn(Observable.just(Collections.emptyList()));
TestSubscriber<List<PackageInfo>> testSubscriber = new TestSubscriber<>();
fetchUpdatedPackages.get().toBlocking().subscribe(testSubscriber);
List<PackageInfo> expectedPackages = Arrays.asList(MockPackageInfo.TEST, MockPackageInfo.TEST2);
List<PackageInfo> receivedPackages = testSubscriber.getOnNextEvents().get(0);
assertThat(receivedPackages).containsAll(expectedPackages);
testSubscriber.assertCompleted();
}
示例13: rxObservableListFall
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void rxObservableListFall() {
server.enqueue(new MockResponse().setResponseCode(500));
TestInterface api = target();
Observable<List<String>> observable = api.listObservable();
assertThat(observable).isNotNull();
assertThat(server.getRequestCount()).isEqualTo(0);
TestSubscriber<List<String>> testSubscriber = new TestSubscriber<List<String>>();
observable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
assertThat(testSubscriber.getOnNextEvents().get(0)).containsExactly("fallback");
}
示例14: testInsertInTxList
import rx.observers.TestSubscriber; //導入依賴的package包/類
public void testInsertInTxList() {
TestEntity foo = RxTestHelper.createEntity("foo");
TestEntity bar = RxTestHelper.createEntity("bar");
List<TestEntity> list = new ArrayList<>();
list.add(foo);
list.add(bar);
TestSubscriber<List<TestEntity>> testSubscriber = RxTestHelper.awaitTestSubscriber(rxDao.insertInTx(list));
assertEquals(1, testSubscriber.getValueCount());
List<TestEntity> result = testSubscriber.getOnNextEvents().get(0);
assertSame(foo, result.get(0));
assertSame(bar, result.get(1));
List<TestEntity> all = dao.loadAll();
assertEquals(2, all.size());
assertEquals(foo.getSimpleStringNotNull(), all.get(0).getSimpleStringNotNull());
assertEquals(bar.getSimpleStringNotNull(), all.get(1).getSimpleStringNotNull());
}
示例15: rxSingle
import rx.observers.TestSubscriber; //導入依賴的package包/類
@Test
public void rxSingle() {
server.enqueue(new MockResponse().setBody("\"foo\""));
TestInterface api = target();
Single<String> single = api.single();
assertThat(single).isNotNull();
assertThat(server.getRequestCount()).isEqualTo(0);
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
single.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
Assertions.assertThat(testSubscriber.getOnNextEvents().get(0)).isEqualTo("foo");
}