本文整理汇总了Java中io.reactivex.observers.TestObserver.assertValueCount方法的典型用法代码示例。如果您正苦于以下问题:Java TestObserver.assertValueCount方法的具体用法?Java TestObserver.assertValueCount怎么用?Java TestObserver.assertValueCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.observers.TestObserver
的用法示例。
在下文中一共展示了TestObserver.assertValueCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executionObservables_noErrors
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void executionObservables_noErrors() {
RxCommand<String> command = RxCommand.create(o -> {
if (o == null) {
return Observable.error(new Exception("something wrong"));
} else {
return Observable.just((String) o);
}
});
TestObserver<Observable<String>> testObserver = new TestObserver<>();
command.executionObservables().subscribe(testObserver);
command.execute(null);
command.execute("1");
command.execute("2");
testObserver.assertValueCount(3);
testObserver.assertNoErrors();
testObserver.assertNotComplete();
}
示例2: testIsPageBookmarked
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testIsPageBookmarked() {
when(bookmarksAdapter.getBookmarkId(null, null, 42)).thenReturn(1L);
when(bookmarksAdapter.getBookmarkId(null, null, 43)).thenReturn(-1L);
TestObserver<Pair<Integer, Boolean>> testObserver = new TestObserver<>();
model.getIsBookmarkedObservable(42, 43)
.subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertValueCount(2);
List<Pair<Integer, Boolean>> results = testObserver.values();
for (int i = 0; i < results.size(); i++) {
Pair<Integer, Boolean> result = results.get(i);
assertThat(result.first).isAnyOf(42, 43);
if (result.first == 42) {
assertThat(result.second).isTrue();
} else if (result.first == 43) {
assertThat(result.second).isFalse();
}
}
}
示例3: loginTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* {@link NetworkManager} integration test: login request to, local REST API server mock
*/
@Test
public void loginTest() throws Exception{
networkManager.configAuth(dummyApiUrl, dummyLogin, dummyPassword);
Gson gson = new Gson();
AccessToken expectedAccessToken
= gson.fromJson(readAssetFile(testContext, "api/login.json"), AccessToken.class);
TestObserver<AccessToken> testObserver = new CustomTestObserver<>(expectedAccessToken);
networkManager.getAccessToken().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例4: onUserQuery_2subsequentQueriesProvided_shouldPost2EventsWithQueryString
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void onUserQuery_2subsequentQueriesProvided_shouldPost2EventsWithQueryString() {
// given
TestObserver<UserQueryEvent> userQuery$ = TestObserver.create();
PublishSubject<String> userQueryIntents = PublishSubject.create();
given(view.queryInput$()).willReturn(userQueryIntents);
UserQueryPresenter presenter = new UserQueryPresenter(Sink.of(userQuery$));
presenter.start(view);
// when
userQueryIntents.onNext("foo");
userQueryIntents.onNext("bar");
// then
userQuery$.assertValueCount(2);
List<UserQueryEvent> events = userQuery$.values();
assertThat(events)
.extracting(UserQueryEvent::getQuery)
.containsExactly("foo", "bar");
}
示例5: test_just_new
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void test_just_new() {
Observable<Integer> observable = Observable.just(12, 34, 6);
TestObserver<Integer> testObserver = new TestObserver<>();
observable.subscribe(testObserver);
List<Integer> list = new ArrayList();
testObserver.assertComplete();
testObserver.assertResult(12, 34, 6);
testObserver.assertValueCount(3);
testObserver.assertNoErrors();
testObserver.assertValueAt(2, (value) -> {
// TODO Auto-generated method stub
return value == 34;
});
}
示例6: testDataChangesOfClazz
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test public void testDataChangesOfClazz() {
TestObserver<Optional<String>> sub = TestObserver.create();
RxFirebaseDatabase.dataChangesOf(mockDatabaseReference, String.class).subscribe(sub);
verifyAddValueEventListener();
callValueEventOnDataChange("Foo");
sub.assertNotComplete();
sub.assertValueCount(1);
sub.assertValue(new Predicate<Optional<String>>() {
@Override public boolean test(Optional<String> stringOptional) throws Exception {
return stringOptional.isPresent() && "Foo".equals(stringOptional.get());
}
});
sub.dispose();
callValueEventOnDataChange("Foo");
// Ensure no more values are emitted after unsubscribe
sub.assertValueCount(1);
}
示例7: testParseUriWithException
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testParseUriWithException() throws FileNotFoundException {
ParcelFileDescriptor pfd = mock(ParcelFileDescriptor.class);
when(pfd.getFd()).thenReturn(-1);
ContentResolver resolver = mock(ContentResolver.class);
when(resolver.openFileDescriptor(any(Uri.class), anyString())).thenReturn(pfd);
when(appContext.getContentResolver()).thenReturn(resolver);
TestObserver<BufferedSource> observer = new TestObserver<>();
presenter.parseUri(Uri.EMPTY)
.subscribe(observer);
observer.awaitTerminalEvent();
observer.assertError(NullPointerException.class);
observer.assertValueCount(0);
}
示例8: getRemoteTranslationListObservable
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void getRemoteTranslationListObservable() throws Exception {
MockResponse mockResponse = new MockResponse();
File file = new File(CLI_ROOT_DIRECTORY, "translations.json");
Buffer buffer = new Buffer();
buffer.writeAll(Okio.source(file));
mockResponse.setBody(buffer);
this.mockWebServer.enqueue(mockResponse);
TestObserver<TranslationList> testObserver = new TestObserver<>();
this.translationManager.getRemoteTranslationListObservable()
.subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
TranslationList list = testObserver.values().get(0);
assertThat(list.translations).hasSize(50);
}
示例9: testData
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test public void testData() {
TestObserver<DataSnapshot> sub = TestObserver.create();
RxFirebaseDatabase.data(mockDatabaseReference).subscribe(sub);
verifyAddListenerForSingleValueEvent();
callValueEventOnDataChange("Foo");
sub.dispose();
// Ensure no more values are emitted after unsubscribe
callValueEventOnDataChange("Foo");
sub.assertNoErrors();
sub.assertComplete();
sub.assertValueCount(1);
}
示例10: testMakingObservablesTestable
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testMakingObservablesTestable() throws IOException, InterruptedException {
String fakeData = "Date,Open,High,Low,Close,Volume\n" +
"10-Oct-17,1097.00,1123.00,1097.00,1110.00,11978\n" +
"9-Oct-17,1112.00,1120.00,1112.00,1120.00,5660\n" +
"6-Oct-17,1110.00,1110.00,1104.00,1104.00,1537\n" +
"5-Oct-17,1078.00,1105.00,1078.00,1105.00,8134\n";
Observable<Tuple2<String, Double>> tuple2Observable = processStock(Arrays.asList("M", "ATT"), s -> fakeData);
tuple2Observable.subscribe(x -> System.out.println("sub: " + x));
TestObserver<Tuple2<String, Double>> testObserver = new TestObserver<>();
tuple2Observable.subscribe(testObserver);
Thread.sleep(1000);
testObserver.assertNoErrors();
testObserver.assertValueCount(2);
testObserver.assertValueSequence(Arrays.asList(new Tuple2<>("M", 1110.0), new Tuple2<>("ATT", 1110.0)));
Thread.sleep(1000);
}
示例11: testExists
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testExists() throws Exception {
RxPaperBook book = RxPaperBook.with("EXISTS", Schedulers.trampoline());
final String key = "hello";
book.write(key, ComplexObject.random()).subscribe();
final TestObserver<Boolean> foundSubscriber = book.exists(key).test();
foundSubscriber.awaitTerminalEvent();
foundSubscriber.assertNoErrors();
foundSubscriber.assertValueCount(1);
foundSubscriber.assertValues(true);
// notFoundSubscriber
String noKey = ":(";
final TestObserver<Boolean> notFoundSubscriber = book.exists(noKey).test();
notFoundSubscriber.awaitTerminalEvent();
notFoundSubscriber.assertComplete();
notFoundSubscriber.assertValueCount(1);
notFoundSubscriber.assertValues(false);
}
示例12: testDataOfGenericTypeIndicator
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test public void testDataOfGenericTypeIndicator() {
List<String> values = new ArrayList<>();
values.add("Foo");
values.add("Bar");
GenericTypeIndicator<List<String>> typeIndicator = new GenericTypeIndicator<List<String>>() {
};
TestObserver<Optional<List<String>>> sub = TestObserver.create();
RxFirebaseDatabase.dataOf(mockDatabaseReference, typeIndicator).subscribe(sub);
verifyAddListenerForSingleValueEvent();
callValueEventOnDataChange(typeIndicator, values);
sub.assertComplete();
sub.assertNoErrors();
sub.assertValue(new Predicate<Optional<List<String>>>() {
@Override public boolean test(Optional<List<String>> listOptional) throws Exception {
return listOptional.isPresent() && "Foo".equals(listOptional.get().get(0)) && "Bar".equals(
listOptional.get().get(1));
}
});
sub.dispose();
callValueEventOnDataChange(typeIndicator, values);
// Ensure no more values are emitted after unsubscribe
sub.assertValueCount(1);
}
示例13: usingTestObserver
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void usingTestObserver() {
//An Observable with 5 one-second emissions
Observable<Long> source = Observable.interval(1,
TimeUnit.SECONDS)
.take(5);
//Declare TestObserver
TestObserver<Long> testObserver = new TestObserver<>();
//Assert no subscription has occurred yet
testObserver.assertNotSubscribed();
//Subscribe TestObserver to source
source.subscribe(testObserver);
//Assert TestObserver is subscribed
testObserver.assertSubscribed();
//Block and wait for Observable to terminate
testObserver.awaitTerminalEvent();
//Assert TestObserver called onComplete()
testObserver.assertComplete();
//Assert there were no errors
testObserver.assertNoErrors();
//Assert 5 values were received
testObserver.assertValueCount(5);
//Assert the received emissions were 0, 1, 2, 3, 4
testObserver.assertValues(0L, 1L, 2L, 3L, 4L);
}
示例14: loadCollections
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void loadCollections() {
CollectionsResponse responseModel = TestModels.getCollectionsResponse(5);
when(apiInterface.getCollections(ArgumentMatchers.<String, String>anyMap()))
.thenReturn( Observable.just(responseModel));
TestObserver<CollectionsResponse> testSubscriber = new TestObserver<>();
appApiHelper.getCollections(options).subscribe(testSubscriber);
testSubscriber.assertNoErrors();
testSubscriber.assertComplete();
testSubscriber.assertValueCount(1);
testSubscriber.assertValue(responseModel);
}
示例15: shouldReceiveBroadcast
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void shouldReceiveBroadcast() {
//GIVEN
final TestObserver<Intent> observer = RxBroadcastReceivers.fromIntentFilter(application, testIntentFilter)
.test();
//WHEN
application.sendBroadcast(testIntent1);
application.sendBroadcast(testIntent2);
application.sendBroadcast(testIntent3);
//THEN
observer.assertValueCount(3);
observer.assertValues(testIntent1, testIntent2, testIntent3);
}