當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。