本文整理匯總了Java中rx.observers.TestSubscriber.create方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.create方法的具體用法?Java TestSubscriber.create怎麽用?Java TestSubscriber.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.observers.TestSubscriber
的用法示例。
在下文中一共展示了TestSubscriber.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetInvalidJobId
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@SuppressLint("ApplySharedPref")
@Test
public void testGetInvalidJobId() throws Exception {
final Job test = createTestJob();
final String json = gson.toJson(test);
final String key = SimpleUploadDataStore.jobIdKey(test.id());
final Set<String> keys = new HashSet<>();
keys.add(key);
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys);
editor.putString(key, json);
editor.commit();
final TestSubscriber<Job> ts = TestSubscriber.create();
dataStore.get("bad_id").subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertNoErrors();
ts.assertValueCount(1);
ts.assertValue(Job.INVALID_JOB);
}
示例2: fetchSuggestionsTransformerTest
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void fetchSuggestionsTransformerTest() throws Exception {
final Observable<List<String>> listObservable = Observable
.just("1", "2", "3")
.concatMap(each -> Observable.just(each).delay(5, TimeUnit.SECONDS))
.compose(RxSuggestions.suggestionsTransformer());
final TestSubscriber<List<String>> testSubscriber = TestSubscriber.create();
listObservable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
if (Util.isOnline()) {
testSubscriber.assertNoErrors();
assertTrue(testSubscriber.getOnNextEvents().size() == 3);
assertAllListContentsNotEmpty(testSubscriber);
} else {
testSubscriber.assertValueCount(3);
assertTrue(testSubscriber.getOnNextEvents().size() == 3);
testSubscriber.assertNoErrors();
// Transformer swallows error to continue stream.
for (List<String> suggestions : testSubscriber.getOnNextEvents()) {
assertTrue(suggestions.isEmpty());
}
}
}
示例3: update
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void update() throws Exception {
final Job test = createTestJob();
final String json = gson.toJson(test);
final String key = SimpleUploadDataStore.jobIdKey(test.id());
final Set<String> keys = new HashSet<>();
keys.add(key);
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys);
editor.putString(key, json);
editor.apply();
final TestSubscriber<Job> ts = TestSubscriber.create();
dataStore.update(Status.createCompleted(test.id(), null)).subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertNoErrors();
ts.assertValueCount(1);
ts.assertValue(test.withStatus(Status.createCompleted(test.id(), null)));
}
示例4: 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();
}
示例5: testUploadJobNotFound
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUploadJobNotFound() throws Exception {
final String jobId = "job-id";
when(dataStore.get(jobId)).thenReturn(Observable.just(Job.INVALID_JOB));
final TestSubscriber<Status> ts = TestSubscriber.create();
uploadInteractor.upload(jobId).subscribe(ts);
testScheduler.triggerActions();
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertNoErrors();
ts.assertValueCount(1);
ts.assertValue(Status.createInvalid(jobId));
verify(uploader, times(0)).upload(any(Job.class), any(File.class));
}
示例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: testGet
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@SuppressLint("ApplySharedPref")
@Test
public void testGet() throws Exception {
final Job test = createTestJob();
final String json = gson.toJson(test);
final String key = SimpleUploadDataStore.jobIdKey(test.id());
final Set<String> keys = new HashSet<>();
keys.add(key);
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys);
editor.putString(key, json);
editor.commit();
final TestSubscriber<Job> ts = TestSubscriber.create();
dataStore.get(test.id()).subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertNoErrors();
ts.assertValueCount(1);
ts.assertValue(test);
}
示例8: delete
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@SuppressLint("ApplySharedPref")
@Test
public void delete() throws Exception {
final Job test = createTestJob();
final String json = gson.toJson(test);
final String key = SimpleUploadDataStore.jobIdKey(test.id());
final Set<String> keys = new HashSet<>();
keys.add(key);
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys);
editor.putString(key, json);
editor.commit();
final TestSubscriber<Job> ts = TestSubscriber.create();
dataStore.delete(test.id()).subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertNoErrors();
ts.assertValueCount(1);
ts.assertValue(test);
final TestSubscriber<Job> ts2 = TestSubscriber.create();
dataStore.getAll().subscribe(ts2);
ts2.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts2.assertNoErrors();
ts2.assertCompleted();
ts2.assertNoValues();
}
示例9: testActivityObservableBindUntilEvent
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void testActivityObservableBindUntilEvent() throws Exception {
final Observable<Object> observable = PublishSubject.create().asObservable();
TestSubscriber<Object> testSubscriber = TestSubscriber.create();
NaviFragment fragment = new TestFragment();
this.presenter.bind(fragment);
startFragment(fragment);
this.presenter.bindUntilEvent(observable, FragmentEvent.STOP, testSubscriber);
fragment.onAttach(null);
assertFalse(testSubscriber.isUnsubscribed());
fragment.onCreate(null);
assertFalse(testSubscriber.isUnsubscribed());
fragment.onViewCreated(null, null);
assertFalse(testSubscriber.isUnsubscribed());
fragment.onStart();
assertFalse(testSubscriber.isUnsubscribed());
fragment.onResume();
assertFalse(testSubscriber.isUnsubscribed());
fragment.onPause();
assertFalse(testSubscriber.isUnsubscribed());
fragment.onStop();
testSubscriber.assertCompleted();
testSubscriber.assertUnsubscribed();
fragment.onDestroyView();
testSubscriber.assertCompleted();
testSubscriber.assertUnsubscribed();
}
示例10: save
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void save() throws Exception {
final Job job = Job.builder()
.setId("job_id_1")
.setFilepath("test/file/path/1")
.setMetadata(Collections.emptyMap())
.setMimeType("text/plain")
.setStatus(Status.createQueued("job_id_1"))
.build();
final TestSubscriber<Job> ts = TestSubscriber.create();
dataStore.save(job).subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertNoErrors();
ts.assertValueCount(1);
ts.assertValue(job);
final TestSubscriber<Job> ts2 = TestSubscriber.create();
dataStore.getAll().subscribe(ts2);
ts2.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts2.assertNoErrors();
ts2.assertCompleted();
ts2.assertValueCount(1);
ts2.assertValue(job);
}
示例11: fetchSuggestionsNoErrorTest
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void fetchSuggestionsNoErrorTest() throws Exception {
final TestSubscriber<List<String>> testSubscriber = TestSubscriber.create();
RxSuggestions.fetch("Something").subscribe(testSubscriber);
if (Util.isOnline()) {
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
} else {
assertNoValuesAndOneError(testSubscriber);
}
}
示例12: fetchSuggestionValueReceivedTest
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
public void fetchSuggestionValueReceivedTest() throws Exception {
final TestSubscriber<List<String>> testSubscriber = TestSubscriber.create();
RxSuggestions.fetch("a").subscribe(testSubscriber);
if (Util.isOnline()) {
testSubscriber.assertCompleted();
testSubscriber.assertNoErrors();
final List<List<String>> nextEvents = testSubscriber.getOnNextEvents();
for (String suggestion : nextEvents.get(0)) {
assertTrue(!suggestion.isEmpty());
}
} else {
assertNoValuesAndOneError(testSubscriber);
}
}
示例13: testGlobalSubscription
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@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));
}
示例14: testPlaceSubscription
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testPlaceSubscription() throws Exception {
TestSubscriber<Place> testObserver = TestSubscriber.create();
RxOkuki.onPlace(okuki, TestPlace.class).subscribe(testObserver);
verify(okuki).addPlaceListener(isA(PlaceListener.class));
testObserver.unsubscribe();
verify(okuki).removePlaceListener(isA(PlaceListener.class));
}
示例15: testBranchSubscription
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testBranchSubscription() throws Exception {
TestSubscriber<Place> testObserver = TestSubscriber.create();
RxOkuki.onBranch(okuki, TestPlace.class).subscribe(testObserver);
verify(okuki).addBranchListener(isA(BranchListener.class));
testObserver.unsubscribe();
verify(okuki).removeBranchListener(isA(BranchListener.class));
}