io.reactivex.subjects.Subject.test()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中io.reactivex.subjects.Subject.test()方法的一些代码示例,展示了Subject.test()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Subject.test()方法的具体详情如下:
包路径:io.reactivex.subjects.Subject
类名称:Subject
方法名:test

Subject.test介绍

暂无

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void onErrorNull() {
    Subject<T> p = create();

    try {
      p.onError(null);
      fail("No NullPointerException thrown");
    } catch (NullPointerException ex) {
      assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
    }

    p.test().assertEmpty().cancel();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onNextNull() {
  Subject<T> p = create();
  try {
    p.onNext(null);
    fail("No NullPointerException thrown");
  } catch (NullPointerException ex) {
    assertEquals("onNext called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
  }
  p.test().assertEmpty().cancel();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onCompleteOnCompleteRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        s.onComplete();
      }
    };
    Runnable r2 = new Runnable() {
      @Override
      public void run() {
        s.onComplete();
      }
    };
    TestHelper.race(r1, r2);
    to.assertResult();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onNextOnNextRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        s.onNext(1);
      }
    };
    Runnable r2 = new Runnable() {
      @Override
      public void run() {
        s.onNext(2);
      }
    };
    TestHelper.race(r1, r2);
    to.assertSubscribed().assertNoErrors().assertNotComplete()
    .assertValueSet(Arrays.asList(1, 2));
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onCompleteOnSubscribeRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    final Disposable bs = Disposables.empty();
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        s.onComplete();
      }
    };
    Runnable r2 = new Runnable() {
      @Override
      public void run() {
        s.onSubscribe(bs);
      }
    };
    TestHelper.race(r1, r2);
    to.assertResult();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void onSubscribeOnSubscribeRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
      final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();

      TestObserver<Integer> to = s.test();

      final Disposable bs1 = Disposables.empty();
      final Disposable bs2 = Disposables.empty();

      Runnable r1 = new Runnable() {
        @Override
        public void run() {
          s.onSubscribe(bs1);
        }
      };

      Runnable r2 = new Runnable() {
        @Override
        public void run() {
          s.onSubscribe(bs2);
        }
      };

      TestHelper.race(r1, r2);

      to.assertEmpty();
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onNextOnSubscribeRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    final Disposable bs = Disposables.empty();
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        s.onNext(1);
      }
    };
    Runnable r2 = new Runnable() {
      @Override
      public void run() {
        s.onSubscribe(bs);
      }
    };
    TestHelper.race(r1, r2);
    to.assertValue(1).assertNotComplete().assertNoErrors();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onNextOnCompleteRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        s.onNext(1);
      }
    };
    Runnable r2 = new Runnable() {
      @Override
      public void run() {
        s.onComplete();
      }
    };
    TestHelper.race(r1, r2);
    to.assertComplete().assertNoErrors();
    if (to.valueCount() != 0) {
      to.assertValue(1);
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onNextOnErrorRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    final TestException ex = new TestException();
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        s.onNext(1);
      }
    };
    Runnable r2 = new Runnable() {
      @Override
      public void run() {
        s.onError(ex);
      }
    };
    TestHelper.race(r1, r2);
    to.assertError(ex).assertNotComplete();
    if (to.valueCount() != 0) {
      to.assertValue(1);
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onErrorOnErrorRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    final TestException ex = new TestException();
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
      Runnable r1 = new Runnable() {
        @Override
        public void run() {
          s.onError(ex);
        }
      };
      Runnable r2 = new Runnable() {
        @Override
        public void run() {
          s.onError(ex);
        }
      };
      TestHelper.race(r1, r2);
      to.assertFailure(TestException.class);
      TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
      RxJavaPlugins.reset();
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void normal() {
  Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
  TestObserver<Integer> to = s.test();
  Observable.range(1, 10).subscribe(s);
  to.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  assertFalse(s.hasObservers());
  s.onNext(11);
  List<Throwable> errors = TestHelper.trackPluginErrors();
  try {
    s.onError(new TestException());
    TestHelper.assertUndeliverable(errors, 0, TestException.class);
  } finally {
    RxJavaPlugins.reset();
  }
  s.onComplete();
  Disposable bs = Disposables.empty();
  s.onSubscribe(bs);
  assertTrue(bs.isDisposed());
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void sj1ToSj2NullValue() {
  rx.subjects.PublishSubject<Integer> ps1 = rx.subjects.PublishSubject.create();
  io.reactivex.subjects.Subject<Integer> sj2 = toV2Subject(ps1);
  io.reactivex.observers.TestObserver<Integer> to = sj2.test();
  sj2.onNext(null);
  assertFalse(sj2.hasObservers());
  assertFalse(ps1.hasObservers());
  to.assertFailure(NullPointerException.class);
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void sj1ToSj2NullException() {
  rx.subjects.PublishSubject<Integer> ps1 = rx.subjects.PublishSubject.create();
  io.reactivex.subjects.Subject<Integer> sj2 = toV2Subject(ps1);
  io.reactivex.observers.TestObserver<Integer> to = sj2.test();
  sj2.onError(null);
  assertFalse(sj2.hasObservers());
  assertFalse(ps1.hasObservers());
  to.assertFailure(NullPointerException.class);
}

代码示例来源:origin: akarnokd/RxJava2Extensions

@Override
  public void run() {
    rcp.test().cancel();
  }
};

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void sj1ToSj2Error() {
  rx.subjects.PublishSubject<Integer> ps1 = rx.subjects.PublishSubject.create();
  io.reactivex.subjects.Subject<Integer> sj2 = toV2Subject(ps1);
  io.reactivex.observers.TestObserver<Integer> to = sj2.test();
  assertTrue(sj2.hasObservers());
  assertTrue(ps1.hasObservers());
  assertFalse(sj2.hasComplete());
  assertFalse(sj2.hasThrowable());
  assertNull(sj2.getThrowable());
  sj2.onError(new IOException());
  assertFalse(sj2.hasObservers());
  assertFalse(ps1.hasObservers());
  assertFalse(sj2.hasComplete());
  assertTrue(sj2.hasThrowable());
  assertNotNull(sj2.getThrowable());
  assertTrue(sj2.getThrowable() instanceof IOException);
  to.assertFailure(IOException.class);
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void sj1ToSj2Normal() {
  rx.subjects.PublishSubject<Integer> ps1 = rx.subjects.PublishSubject.create();
  io.reactivex.subjects.Subject<Integer> sj2 = toV2Subject(ps1);
  io.reactivex.observers.TestObserver<Integer> to = sj2.test();
  assertTrue(sj2.hasObservers());
  assertTrue(ps1.hasObservers());
  assertFalse(sj2.hasComplete());
  assertFalse(sj2.hasThrowable());
  assertNull(sj2.getThrowable());
  sj2.onNext(1);
  sj2.onNext(2);
  sj2.onComplete();
  assertFalse(sj2.hasObservers());
  assertFalse(ps1.hasObservers());
  assertTrue(sj2.hasComplete());
  assertFalse(sj2.hasThrowable());
  assertNull(sj2.getThrowable());
  to.assertResult(1, 2);
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void sj1ToSj2Lifecycle() {
  rx.subjects.PublishSubject<Integer> ps1 = rx.subjects.PublishSubject.create();
  io.reactivex.subjects.Subject<Integer> sj2 = toV2Subject(ps1);
  io.reactivex.observers.TestObserver<Integer> to = sj2.test();
  assertTrue(sj2.hasObservers());
  assertTrue(ps1.hasObservers());
  assertFalse(sj2.hasComplete());
  assertFalse(sj2.hasThrowable());
  assertNull(sj2.getThrowable());
  Disposable d1 = Disposables.empty();
  sj2.onSubscribe(d1);
  assertFalse(d1.isDisposed());
  sj2.onNext(1);
  sj2.onNext(2);
  sj2.onComplete();
  sj2.onComplete();
  sj2.onError(new IOException());
  sj2.onNext(3);
  Disposable d2 = Disposables.empty();
  sj2.onSubscribe(d2);
  assertFalse(d1.isDisposed());
  assertTrue(d2.isDisposed());
  assertFalse(sj2.hasObservers());
  assertFalse(ps1.hasObservers());
  assertTrue(sj2.hasComplete());
  assertFalse(sj2.hasThrowable());
  assertNull(sj2.getThrowable());
  to.assertResult(1, 2);
}

代码示例来源:origin: akarnokd/akarnokd-misc

@Test
  public void test() {
    rx.subjects.PublishSubject<String> sj = rx.subjects.PublishSubject.create();
    io.reactivex.subjects.Subject<String> sj2 = RxJavaInterop.toV2Subject(sj);
    sj2.test();
  }
}

代码示例来源:origin: akarnokd/RxJava2Extensions

@Test
public void multipleSubscribers() {
  Subject<Integer> rcp = Subjects.refCount(PublishSubject.<Integer>create());
  PublishSubject<Integer> source = PublishSubject.create();
  source.subscribe(rcp);
  assertTrue(source.hasObservers());
  TestObserver<Integer> to1 = rcp.test();
  TestObserver<Integer> to2 = rcp.test();
  to1.cancel();
  assertTrue(source.hasObservers());
  to2.cancel();
  assertFalse(source.hasObservers());
  rcp.test().assertFailureAndMessage(IllegalStateException.class, "RefCountSubject terminated");
}

代码示例来源:origin: akarnokd/RxJava2Extensions

@Test
public void immediatelyCancelled() {
  Subject<Integer> rcp = Subjects.refCount(PublishSubject.<Integer>create());
  PublishSubject<Integer> source = PublishSubject.create();
  source.subscribe(rcp);
  assertTrue(source.hasObservers());
  rcp.test(true);
  assertFalse(source.hasObservers());
}

相关文章