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


Java PublishSubject.onCompleted方法代码示例

本文整理汇总了Java中rx.subjects.PublishSubject.onCompleted方法的典型用法代码示例。如果您正苦于以下问题:Java PublishSubject.onCompleted方法的具体用法?Java PublishSubject.onCompleted怎么用?Java PublishSubject.onCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rx.subjects.PublishSubject的用法示例。


在下文中一共展示了PublishSubject.onCompleted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: basic

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void basic() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  o.assertNoMoreEvents();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();

  subject.onCompleted();
  o.assertOnCompleted();
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:22,代码来源:OperatorNormalizeTest.java

示例2: completion

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void completion() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  // First emits immediately
  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  subject.onCompleted();
  o.assertNoMoreEvents();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertOnCompleted();
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:22,代码来源:OperatorNormalizeTest.java

示例3: refresh

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void refresh() throws Exception {
    final Reddit reddit = new Reddit();
    PublishSubject<Reddit> subject = PublishSubject.create();
    Mockito.doReturn(subject.asObservable().toList())
            .when(mRepository)
            .getReddits(Mockito.anyString());
    mViewModel.refresh();
    Mockito.verify(mRepository).getReddits("test");
    Assert.assertThat(mViewModel.errorText.get(), IsNull.nullValue());
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(true));
    subject.onNext(reddit);
    subject.onCompleted();
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(false));
    Assert.assertThat(mViewModel.reddits, IsCollectionContaining.hasItems(reddit));
}
 
开发者ID:DanielSerdyukov,项目名称:droidcon2016,代码行数:17,代码来源:RedditListViewModelTest.java

示例4: searchQueryChange

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void searchQueryChange() throws Exception {
    final Subreddit subreddit = new Subreddit();
    PublishSubject<Subreddit> subject = PublishSubject.create();
    Mockito.doReturn(subject.asObservable().toList())
            .when(mRepository)
            .searchSubreddits(Mockito.anyString());
    mViewModel.subscribeOnSearchQueryChange();
    mViewModel.mSearchQuery.onNext("test");
    Mockito.verify(mRepository).searchSubreddits("test");
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(true));
    subject.onNext(subreddit);
    subject.onCompleted();
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(false));
    Assert.assertThat(mViewModel.subreddits, IsCollectionContaining.hasItems(subreddit));
}
 
开发者ID:DanielSerdyukov,项目名称:droidcon2016,代码行数:17,代码来源:MainViewModelTest.java

示例5: testEmitsCompleted

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testEmitsCompleted() {
  final PublishSubject<Integer> source = PublishSubject.create();
  final Observable<Void> result = source
    .materialize()
    .compose(Transformers.completed());

  final TestSubscriber<Void> resultTest = new TestSubscriber<>();
  result.subscribe(resultTest);

  source.onNext(1);
  resultTest.assertNoValues();

  // Only emit when a completed notification occurs.
  source.onCompleted();
  resultTest.assertValueCount(1);
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:18,代码来源:CompletedTransformerTest.java

示例6: testEmitsOnNext

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testEmitsOnNext() {
  final PublishSubject<Integer> source = PublishSubject.create();
  final Observable<Integer> result = source
    .materialize()
    .compose(Transformers.values());

  final TestSubscriber<Integer> resultTest = new TestSubscriber<>();
  result.subscribe(resultTest);

  // onNext should emit values.
  source.onNext(1);
  resultTest.assertValues(1);

  source.onNext(2);
  resultTest.assertValues(1, 2);

  // Completing the source stream should not emit values.
  source.onCompleted();
  resultTest.assertValues(1, 2);
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:22,代码来源:ValuesTransformerTest.java

示例7: onRequestPermissionsResult

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        log("onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onCompleted();
    }
}
 
开发者ID:why168,项目名称:AndroidProjects,代码行数:17,代码来源:RxPermissionsFragment.java

示例8: testFromLazyIterator

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testFromLazyIterator() throws InterruptedException {
  PublishSubject<Integer> o1 = PublishSubject.create();
  AtomicBoolean fetched = new AtomicBoolean();
  Iterator<Integer> iter = Iterators.filter(Arrays.asList(1,2,3).iterator(), item->{fetched.set(true); return true;});
  CountDownLatch latch = new CountDownLatch(3);
  AtomicReference<Throwable> error = new AtomicReference<>();
  Observable<Integer> o2 = RxGuava.fromIterator(()->Futures.immediateFuture(iter), executor);
  Observable.concat(o1, o2).subscribe(item->latch.countDown(),e->error.set(e));
  Thread.sleep(100);
  Assert.assertFalse("lazy future should not have been fetched yet", fetched.get());
  o1.onCompleted(); //should trigger lazy future to compute
  Thread.sleep(50);
  Assert.assertTrue("lazy future should have been fetched by now", fetched.get());
  Assert.assertNull(error.get());
}
 
开发者ID:ybayk,项目名称:rxjava-recipes,代码行数:17,代码来源:RxGuavaTest.java

示例9: testFromLazyIterable

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testFromLazyIterable() throws InterruptedException {
  PublishSubject<Integer> o1 = PublishSubject.create();
  AtomicBoolean fetched = new AtomicBoolean();
  List<Integer> list = Arrays.asList(1,2,3);
  Iterable<Integer> iterable = new Iterable<Integer>() {

    @Override
    public Iterator<Integer> iterator() {
      fetched.set(true);
      return list.iterator();
    }
    
  };
  CountDownLatch latch = new CountDownLatch(3);
  AtomicReference<Throwable> error = new AtomicReference<>();
  Observable<Integer> o2 = RxGuava.fromIterable(()->Futures.immediateFuture(iterable), executor);
  Observable.concat(o1, o2).subscribe(item->latch.countDown(),e->error.set(e));
  Thread.sleep(100);
  Assert.assertFalse("lazy future should not have been fetched yet", fetched.get());
  o1.onCompleted(); //should trigger lazy future to compute
  Thread.sleep(50);
  Assert.assertTrue("lazy future should have been fetched by now", fetched.get());
  Assert.assertNull(error.get());
}
 
开发者ID:ybayk,项目名称:rxjava-recipes,代码行数:26,代码来源:RxGuavaTest.java

示例10: testFromLazyScalar

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testFromLazyScalar() throws Exception {
  PublishSubject<Integer> o1 = PublishSubject.create();
  AtomicBoolean fetched = new AtomicBoolean();
  CountDownLatch latch = new CountDownLatch(3);
  AtomicReference<Throwable> error = new AtomicReference<>();
  Observable<String> o2 = RxGuava.fromScalar(()->{
    fetched.set(true); 
    return Futures.immediateFuture("test");
  }, executor);
  Observable.concat(o1, o2).subscribe(item->latch.countDown(),e->error.set(e));
  Thread.sleep(100);
  Assert.assertFalse("lazy future should not have been fetched yet", fetched.get());
  o1.onCompleted(); //should trigger lazy future to compute
  Thread.sleep(50);
  Assert.assertTrue("lazy future should have been fetched by now", fetched.get());
  Assert.assertNull(error.get());
}
 
开发者ID:ybayk,项目名称:rxjava-recipes,代码行数:19,代码来源:RxGuavaTest.java

示例11: signOut

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
/**
 * Facebook sign out
 */
public void signOut(PublishSubject<RxStatus> statusSubject) {
    LoginManager.getInstance().logOut();
    // delete current user
    deleteCurrentUser();
    statusSubject.onNext(new RxStatus(
            CommonStatusCodes.SUCCESS,
            getString(R.string.status_success_log_out_message)
    ));
    statusSubject.onCompleted();
}
 
开发者ID:pchmn,项目名称:RxSocialAuth,代码行数:14,代码来源:RxFacebookAuthFragment.java

示例12: buffer

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void buffer() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  // First emits immediately
  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  subject.onNext(2);
  subject.onNext(3);
  o.assertNoMoreEvents();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertNoMoreEvents();
  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertNoMoreEvents();
  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertNoMoreEvents();

  subject.onCompleted();
  o.assertOnCompleted();
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:32,代码来源:OperatorNormalizeTest.java

示例13: testCompletedDoesNotEmitAnErrorNotification

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testCompletedDoesNotEmitAnErrorNotification() {
  final PublishSubject<Integer> source = PublishSubject.create();
  final Observable<Throwable> result = source
    .materialize()
    .compose(Transformers.errors());

  final TestSubscriber<Throwable> resultTest = new TestSubscriber<>();
  result.subscribe(resultTest);

  source.onCompleted();
  resultTest.assertValueCount(0);
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:14,代码来源:ErrorsTransformerTest.java

示例14: onActivityResult

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
void onActivityResult(int requestCode, int resultCode, Intent data) {
    PublishSubject<ActivityResult> subject = results.remove(requestCode);
    ActivityResult result = new ActivityResult(requestCode, resultCode, data);
    subject.onNext(result);
    subject.onCompleted();
}
 
开发者ID:NateWickstrom,项目名称:RxActivityResult,代码行数:7,代码来源:RxActivityResult.java

示例15: emitItem

import rx.subjects.PublishSubject; //导入方法依赖的package包/类
private void emitItem(AuthenticationData authenticationData, Response<Void> response) {
    PublishSubject<Response<Void>> publishSubject = responses.get(authenticationData);
    publishSubject.onNext(response);
    publishSubject.onCompleted();
}
 
开发者ID:savvasdalkitsis,项目名称:Mondo,代码行数:6,代码来源:FakeAuthenticationUseCase.java


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