当前位置: 首页>>代码示例>>Java>>正文


Java TestObserver.assertValueCount方法代码示例

本文整理汇总了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();
}
 
开发者ID:listenzz,项目名称:RxCommand,代码行数:23,代码来源:RxCommandTest.java

示例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();
    }
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:24,代码来源:BookmarkModelTest.java

示例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();
}
 
开发者ID:jakdor,项目名称:LabDayApp,代码行数:20,代码来源:NetworkManagerIntegrationTest.java

示例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");
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:21,代码来源:UserQueryPresenterTest.java

示例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;
	});

}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:19,代码来源:Modern_Testing.java

示例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);
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:24,代码来源:RxFirebaseDatabaseTest.java

示例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);
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:17,代码来源:QuranImportPresenterTest.java

示例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);
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:19,代码来源:TranslationManagerPresenterTest.java

示例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);
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:17,代码来源:RxFirebaseDatabaseTest.java

示例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);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:25,代码来源:ObservableTestingTest.java

示例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);
}
 
开发者ID:pakoito,项目名称:RxPaper2,代码行数:19,代码来源:RxPaperBookTest.java

示例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);
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:33,代码来源:RxFirebaseDatabaseTest.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:35,代码来源:Ch10_12.java

示例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);
}
 
开发者ID:graviton57,项目名称:TheNounProject,代码行数:16,代码来源:ApiHelperTest.java

示例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);
}
 
开发者ID:karczews,项目名称:RxBroadcastReceiver,代码行数:14,代码来源:RxBroadcastReceiverTest.java


注:本文中的io.reactivex.observers.TestObserver.assertValueCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。