本文整理匯總了Java中rx.observers.TestSubscriber.assertValueCount方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.assertValueCount方法的具體用法?Java TestSubscriber.assertValueCount怎麽用?Java TestSubscriber.assertValueCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.observers.TestSubscriber
的用法示例。
在下文中一共展示了TestSubscriber.assertValueCount方法的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: fetchSuggestionsCountTest
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void fetchSuggestionsCountTest() throws Exception {
final TestSubscriber<List<String>> testSubscriber = TestSubscriber.create();
int maxSuggestions = 1;
RxSuggestions.fetch("a", maxSuggestions).subscribe(testSubscriber);
final List<List<String>> nextEvents = testSubscriber.getOnNextEvents();
if (Util.isOnline()) {
testSubscriber.assertValueCount(1);
testSubscriber.assertCompleted();
testSubscriber.assertNoErrors();
assertTrue(!nextEvents.isEmpty() && nextEvents.size() == 1);
assertTrue(nextEvents.get(0).size() == maxSuggestions);
} else {
testSubscriber.assertNoValues();
assertTrue(testSubscriber.getOnErrorEvents().get(0) instanceof UnknownHostException);
}
}
示例4: testAggregatedStream
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testAggregatedStream() {
TestSubscriber<HystrixCommandCompletion> subscriber = new TestSubscriber<>();
new AggregatedHystrixCommandCompletionStream(notifier, t -> true).observe().subscribe(subscriber);
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();
subscriber.assertValueCount(7);
subscriber.assertNoErrors();
subscriber.assertNoTerminalEvent();
}
開發者ID:ringcentral,項目名稱:hystrix-addons,代碼行數:17,代碼來源:AggregatedHystrixCommandCompletionStreamTest.java
示例5: testAggregatedStreamWithFilter
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testAggregatedStreamWithFilter() {
TestSubscriber<HystrixCommandCompletion> subscriber = new TestSubscriber<>();
new AggregatedHystrixCommandCompletionStream(notifier, c -> c.getCommandKey() == COMMAND_1).observe().subscribe(subscriber);
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
subscriber.assertValueCount(3);
Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();
subscriber.assertValueCount(3);
subscriber.assertNoErrors();
subscriber.assertNoTerminalEvent();
}
開發者ID:ringcentral,項目名稱:hystrix-addons,代碼行數:19,代碼來源:AggregatedHystrixCommandCompletionStreamTest.java
示例6: 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));
}
示例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: 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)));
}
示例9: testViewObservable
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testViewObservable() {
RxPresenter<Integer> presenter = new RxPresenter<>();
presenter.onCreate(null);
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
presenter.view().subscribe(testSubscriber);
testSubscriber.assertValueCount(0);
List<Integer> values = new ArrayList<>();
presenter.onTakeView(1);
values.add(1);
assertValues(values, testSubscriber);
presenter.onDropView();
values.add(null);
assertValues(values, testSubscriber);
presenter.onTakeView(2);
values.add(2);
assertValues(values, testSubscriber);
presenter.onDestroy();
assertValues(values, testSubscriber);
testSubscriber.assertCompleted();
}
示例10: validateSuccess
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
public static <T extends Resource> void validateSuccess(Observable<ResourceResponse<T>> observable,
ResourceResponseValidator<T> validator, long timeout) throws InterruptedException {
TestSubscriber<ResourceResponse<T>> testSubscriber = new TestSubscriber<ResourceResponse<T>>();
observable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors();
testSubscriber.assertCompleted();
testSubscriber.assertValueCount(1);
validator.validate(testSubscriber.getOnNextEvents().get(0));
}
示例11: filteredObservableOnlyReceivesSomeObjects
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void filteredObservableOnlyReceivesSomeObjects() {
TestSubscriber<String> testSubscriber = new TestSubscriber<>();
mEventBus.filteredObservable(String.class).subscribe(testSubscriber);
String stringEvent = "Event";
Integer intEvent = 20;
mEventBus.post(stringEvent);
mEventBus.post(intEvent);
testSubscriber.assertValueCount(1);
testSubscriber.assertValue(stringEvent);
}
示例12: 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);
}
}
示例13: 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);
}
示例14: 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();
}
示例15: testGetAll
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@SuppressLint("ApplySharedPref")
@Test
public void testGetAll() throws Exception {
final Job job1 = 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 Job job2 = Job.builder()
.setId("job_id_2")
.setFilepath("test/file/path/2")
.setMetadata(Collections.emptyMap())
.setMimeType("text/plain")
.setStatus(Status.createCompleted("job_id_2", null))
.build();
final Job job3 = Job.builder()
.setId("job_id_3")
.setFilepath("test/file/path/3")
.setMetadata(Collections.emptyMap())
.setMimeType("text/plain")
.setStatus(Status.createFailed("job_id_3", ErrorType.SERVICE))
.build();
final Set<String> keys = new HashSet<>();
keys.add(SimpleUploadDataStore.jobIdKey(job1.id()));
keys.add(SimpleUploadDataStore.jobIdKey(job2.id()));
keys.add(SimpleUploadDataStore.jobIdKey(job3.id()));
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys);
editor.putString(SimpleUploadDataStore.jobIdKey(job1.id()), gson.toJson(job1));
editor.putString(SimpleUploadDataStore.jobIdKey(job2.id()), gson.toJson(job2));
editor.putString(SimpleUploadDataStore.jobIdKey(job3.id()), gson.toJson(job3));
editor.commit();
final TestSubscriber<Job> ts = TestSubscriber.create();
dataStore.getAll().subscribe(ts);
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertNoErrors();
ts.assertCompleted();
ts.assertValueCount(3);
final List<Job> jobs = ts.getOnNextEvents();
assertThat(jobs, containsInAnyOrder(job1, job2, job3));
}