Java Code Examples for io.reactivex.rxjava3.observers.TestObserver#assertNoErrors()

The following examples show how to use io.reactivex.rxjava3.observers.TestObserver#assertNoErrors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UntilEventTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
@Test
public void twoEvents() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bindUntilEvent(lifecycle, "stop"))
        .test();

    lifecycle.onNext("keep going");
    testObserver.assertNoErrors();

    lifecycle.onNext("stop");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);

    testObserver.assertNoValues();
    testObserver.assertError(CancellationException.class);
}
 
Example 2
Source File: UntilLifecycleTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
@Test
public void oneEvent() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bind(lifecycle))
        .test();

    testObserver.assertNoValues();
    testObserver.assertNoErrors();

    lifecycle.onNext("stop");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);

    testObserver.assertNoValues();
    testObserver.assertError(CancellationException.class);
}
 
Example 3
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 6 votes vote down vote up
@Test
public void rx_ListPopulationMoreThanOneMillionWithTimeoutFallbackToEmpty_When_NoTimeout() throws InterruptedException {
    FutureTask<List<Country>> futureTask = new FutureTask<>(() -> {
        TimeUnit.MILLISECONDS.sleep(100);
        return allCountries;
    });
    new Thread(futureTask).start();
    TestObserver<Country> testObserver = countriesService
            .listPopulationMoreThanOneMillionWithTimeoutFallbackToEmpty(futureTask)
            .test();
    List<Country> expectedResult = CountriesTestProvider.countriesPopulationMoreThanOneMillion();
    testObserver.await();
    testObserver.assertComplete();
    testObserver.assertValueSequence(expectedResult);
    testObserver.assertNoErrors();
}
 
Example 4
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_ListPopulationMoreThanOneMillionWithTimeoutFallbackToEmpty_When_Timeout() throws InterruptedException {
    FutureTask<List<Country>> futureTask = new FutureTask<>(() -> {
        TimeUnit.SECONDS.sleep(15);
        return allCountries;
    });
    new Thread(futureTask).start();
    TestObserver<Country> testObserver = countriesService
            .listPopulationMoreThanOneMillionWithTimeoutFallbackToEmpty(futureTask)
            .test();
    testObserver.await();
    testObserver.assertComplete();
    testObserver.assertNoValues();
    testObserver.assertNoErrors();
}
 
Example 5
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Test
public void timeAndSizeNoTerminalTruncationOnTimechange2() {
    ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1);

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

    rs.accept(1);
    rs.cleanupBuffer();
    rs.accept(2);
    rs.cleanupBuffer();

    to.assertNoErrors();
}
 
Example 6
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Test
public void timeAndSizeNoTerminalTruncationOnTimechange4() {
    ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 10);

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

    rs.accept(1);
    rs.accept(2);

    to.assertNoErrors();
}
 
Example 7
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_areEmittingSameSequences_Negative() {
    List<Country> allCountriesDifferentSequence = new ArrayList<>(allCountries);
    Collections.swap(allCountriesDifferentSequence, 0, 1);
    TestObserver<Boolean> testObserver = countriesService
            .areEmittingSameSequences(
                    Observable.fromIterable(allCountries),
                    Observable.fromIterable(allCountriesDifferentSequence))
            .test();
    testObserver.assertResult(false);
    testObserver.assertNoErrors();
}
 
Example 8
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_areEmittingSameSequences_Positive() {
    // hint: use "sequenceEqual" operator
    TestObserver<Boolean> testObserver = countriesService
            .areEmittingSameSequences(Observable.fromIterable(allCountries), Observable.fromIterable(allCountries))
            .test();
    testObserver.assertResult(true);
    testObserver.assertNoErrors();
}
 
Example 9
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_sumPopulationOfCountries() {
    // hint: use "map" operator
    TestObserver<Long> testObserver = countriesService
            .sumPopulationOfCountries(Observable.fromIterable(allCountries), Observable.fromIterable(allCountries))
            .test();
    testObserver.assertResult(CountriesTestProvider.sumPopulationOfAllCountries()
            + CountriesTestProvider.sumPopulationOfAllCountries());
    testObserver.assertNoErrors();
}
 
Example 10
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Test
public void timeAndSizeNoTerminalTruncationOnTimechange2() {
    ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1);

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

    rs.accept(1);
    rs.cleanupBuffer();
    rs.accept(2);
    rs.cleanupBuffer();

    to.assertNoErrors();
}
 
Example 11
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_GetCurrencyUsdIfNotFound_When_CountryNotFound() {
    String countryRequested = "Senegal";
    String expectedCurrencyValue = "USD";
    TestObserver<String> testObserver = countriesService
            .getCurrencyUsdIfNotFound(countryRequested, allCountries)
            .test();
    testObserver.assertResult(expectedCurrencyValue);
    testObserver.assertNoErrors();
}
 
Example 12
Source File: UntilCorrespondingEventTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void openAndCloseEvent() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    lifecycle.onNext("create");
    testObserver.assertNoErrors();

    lifecycle.onNext("destroy");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    testObserver.assertNoValues();
    testObserver.assertError(CancellationException.class);
}
 
Example 13
Source File: RxMobiusLoopTest.java    From mobius with Apache License 2.0 5 votes vote down vote up
@Test
public void startModelAndEffects() {
  RxMobiusLoop<Integer, String, Boolean> loop =
      new RxMobiusLoop<>(builder, "StartModel", ImmutableSet.of(true, false));
  final TestObserver<String> testObserver = Observable.just(1).compose(loop).test();

  testObserver.awaitCount(2);
  testObserver.assertValues("StartModel", "StartModel1");
  testObserver.assertNoErrors();
  assertEquals(2, connection.valueCount());
  connection.assertValuesInAnyOrder(true, false);
}
 
Example 14
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Test
public void timeAndSizeNoTerminalTruncationOnTimechange4() {
    ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 10);

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

    rs.accept(1);
    rs.accept(2);

    to.assertNoErrors();
}
 
Example 15
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_IsAllCountriesPopulationMoreThanOneMillion_Negative() {
    TestObserver<Boolean> testObserver = countriesService
            .isAllCountriesPopulationMoreThanOneMillion(allCountries)
            .test();
    testObserver.assertResult(false);
    testObserver.assertNoErrors();
}
 
Example 16
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_IsAllCountriesPopulationMoreThanOneMillion_Positive() {
    TestObserver<Boolean> testObserver = countriesService
            .isAllCountriesPopulationMoreThanOneMillion(CountriesTestProvider.countriesPopulationMoreThanOneMillion())
            .test();
    testObserver.assertResult(true);
    testObserver.assertNoErrors();
}
 
Example 17
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_ListOnly3rdAnd4thCountry() {
    List<Country> expectedResult = new ArrayList<>();
    expectedResult.add(allCountries.get(2));
    expectedResult.add(allCountries.get(3));

    TestObserver<Country> testObserver = countriesService
            .listOnly3rdAnd4thCountry(allCountries)
            .test();
    testObserver.assertValueSequence(expectedResult);
    testObserver.assertNoErrors();
}
 
Example 18
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_ListNameOfEachCountry() {
    List<String> expectedResult = CountriesTestProvider.namesOfCountries();
    TestObserver<String> testObserver = countriesService
            .listNameOfEachCountry(allCountries)
            .test();
    testObserver.assertValueSequence(expectedResult);
    testObserver.assertNoErrors();
}
 
Example 19
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_CountAmountOfCountries() {
    Integer expected = CountriesTestProvider.countries().size();
    TestObserver<Integer> testObserver = countriesService
            .countCountries(allCountries)
            .test();
    testObserver.assertNoErrors();
    testObserver.assertValue(expected);
}
 
Example 20
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_CountryNameInCapitals() {
    Country testCountry = CountriesTestProvider.countries().get(0);
    String expected = testCountry.name.toUpperCase(Locale.US);
    TestObserver<String> testObserver = countriesService
            .countryNameInCapitals(testCountry)
            .test();
    testObserver.assertNoErrors();
    testObserver.assertValue(expected);
}