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

The following examples show how to use io.reactivex.observers.TestObserver#values() . 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: DatabaseTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 6 votes vote down vote up
/**
 * Test database creation and reading.
 */
@SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts")
@Test
public void testCreateRetrieve() throws Exception {
    final int id = 100;
    final String title = "Star Wars";
    final MovieDetailsData movie = new MovieDetailsData();
    setMovieFields(movie, id, title);

    final TestObserver<Boolean> testCreateObserver = db.addFavoriteMovie(movie).test();
    testCreateObserver.await().assertComplete().assertNoErrors();

    final TestObserver<MovieData> testRetrieveObserver = db.getFavoriteMovie(id).test();
    testRetrieveObserver.await().assertNoErrors().assertComplete();
    final List<MovieData> result = testRetrieveObserver.values();
    assertNotNull("Result is empty!", result);
    final MovieData returnedMovie = result.get(0);
    assertNotNull("Returned list is empty!", returnedMovie);
    assertEquals("ID does not match!", returnedMovie.getId(), id);
    assertEquals("Title does not match!", returnedMovie.getTitle(), title);
}
 
Example 2
Source File: RxTestUtils.java    From burstkit4j with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> testObservable(Observable<T> observable, int awaitCount) {
    assertNotNull(observable);
    if (awaitCount == 1) {
        return Collections.singletonList(testSingle(observable.firstOrError()));
    }
    // If you don't do this it blocks trying to do the operation and therefore can't observe the results
    observable = observable.subscribeOn(Schedulers.io());
    TestObserver<T> observer = observable.test();
    observer.awaitCount(awaitCount);
    observer.assertNoErrors();
    assertEquals(awaitCount, observer.valueCount());
    observer.values().forEach(Assert::assertNotNull);
    return observer.values();
}
 
Example 3
Source File: RestApiTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfiguration() throws Exception {
    final TestObserver<Configuration> testSubscriber = service.getConfiguration().test();
    testSubscriber.await();
    testSubscriber.assertNoErrors();
    testSubscriber.assertComplete();
    final List<Configuration> result = testSubscriber.values();
    assertNotNull("Configuration result is null.", result);
    final Configuration config = result.get(0);
    assertNotNull("Configuration data is null.", config);
    assertNotNull("Configuration for images is null.", config.getImageConfig());
    final String imageBaseUrl = config.getImageConfig().getBaseUrl();
    assertNotNull("Configuration for image base URL is null.", imageBaseUrl);
}
 
Example 4
Source File: RestApiTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNowPlaying() throws Exception {
    final TestObserver<PagingEnvelope<MovieData>> testSubscriber = service.getMovieNowPlaying(null).test();
    testSubscriber.await();
    testSubscriber.assertNoErrors();
    testSubscriber.assertComplete();
    final List<PagingEnvelope<MovieData>> result = testSubscriber.values();
    assertNotNull("Now playing result is null.", result);
    final PagingEnvelope<MovieData> movies = result.get(0);
    assertNotNull("Now Playing movie data is null.", movies);
    assertEquals("Page of the Now Playing movie is null.", movies.getPage(), 1);
    assertNotNull("Now playing movie's results is null.", movies.getResults());
}
 
Example 5
Source File: RestApiTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@Test
public void testMovieDetails() throws Exception {
    final int id = 209112;
    final TestObserver<MovieDetailsData> testSubscriber = service.getMovieDetails(id).test();
    testSubscriber.await();
    testSubscriber.assertNoErrors();
    testSubscriber.assertComplete();
    final List<MovieDetailsData> result = testSubscriber.values();
    assertNotNull("Movie details result is null.", result);
    final MovieDetailsData movieDetails = result.get(0);
    assertNotNull("Movie details data is null.", movieDetails);
    assertEquals("Movie details' ID does not match.", movieDetails.getId(), id);
    assertNotNull("Movie details' title does not match.", movieDetails.getTitle());
}
 
Example 6
Source File: RestApiTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimilarMovies() throws Exception {
    final int id = 209112;
    final TestObserver<PagingEnvelope<MovieData>> testSubscriber = service.getSimilarMovies(id, null).test();
    testSubscriber.await();
    testSubscriber.assertNoErrors();
    testSubscriber.assertComplete();
    final List<PagingEnvelope<MovieData>> result = testSubscriber.values();
    assertNotNull("Similar movies result is null.", result);
    final PagingEnvelope<MovieData> movies = result.get(0);
    assertNotNull("Similar movies data is null.", movies);
    assertEquals("Similar movies page is null.", movies.getPage(), 1);
    assertNotNull("Similar movies' results is null.", movies.getResults());
}
 
Example 7
Source File: TestEmployeeRxJavaService.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Test
public void testEmployeeDataRx(){
	TestObserver<Employee> testObserver = new TestObserver<>();
	employeeRxJavaServiceImpl.getEmployeesRx().subscribe(testObserver);

	testObserver.assertNoErrors();
	List<Employee> emps = testObserver.values();
	for(Employee emp: emps){
		System.out.println(emp.getFirstName());
	}
}
 
Example 8
Source File: GetOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void getExistedObjectExecuteAsSingle() {
    final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem expectedItem = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, expectedItem.toContentValues());
    contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value1").toContentValues());
    contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value2").toContentValues());

    Single<Optional<TestItem>> testItemSingle = storIOContentResolver
            .get()
            .object(TestItem.class)
            .withQuery(Query.builder()
                    .uri(TestItem.CONTENT_URI)
                    .where(TestItem.COLUMN_VALUE + "=?")
                    .whereArgs("value")
                    .build())
            .prepare()
            .asRxSingle();

    TestObserver<Optional<TestItem>> testObserver = new TestObserver<Optional<TestItem>>();
    testItemSingle.subscribe(testObserver);

    testObserver.awaitTerminalEvent(5, SECONDS);
    testObserver.assertNoErrors();

    List<Optional<TestItem>> emmitedItems = testObserver.values();
    assertThat(emmitedItems.size()).isEqualTo(1);
    assertThat(expectedItem.equalsWithoutId(emmitedItems.get(0).get())).isTrue();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 9
Source File: GetOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void getExistedObjectExecuteAsMaybe() {
    final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem expectedItem = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, expectedItem.toContentValues());
    contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value1").toContentValues());
    contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value2").toContentValues());

    Maybe<TestItem> testItemMaybe = storIOContentResolver
            .get()
            .object(TestItem.class)
            .withQuery(Query.builder()
                    .uri(TestItem.CONTENT_URI)
                    .where(TestItem.COLUMN_VALUE + "=?")
                    .whereArgs("value")
                    .build())
            .prepare()
            .asRxMaybe();

    TestObserver<TestItem> testObserver = new TestObserver<TestItem>();
    testItemMaybe.subscribe(testObserver);

    testObserver.awaitTerminalEvent(5, SECONDS);
    testObserver.assertNoErrors();

    List<TestItem> emmitedItems = testObserver.values();
    assertThat(emmitedItems.size()).isEqualTo(1);
    assertThat(expectedItem.equalsWithoutId(emmitedItems.get(0))).isTrue();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 10
Source File: GetOperationTest.java    From storio with Apache License 2.0 4 votes vote down vote up
@Test
public void getCursorAsSingleOnlyInitialValue() {
    final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem testItemToInsert = TestItem.create(null, "value");

    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());

    final TestObserver<Cursor> cursorTestObserver = new TestObserver<Cursor>();

    storIOContentResolver
            .get()
            .cursor()
            .withQuery(Query.builder()
                    .uri(TestItem.CONTENT_URI)
                    .build())
            .prepare()
            .asRxSingle()
            .subscribe(cursorTestObserver);

    cursorTestObserver.awaitTerminalEvent(60, SECONDS);
    cursorTestObserver.assertNoErrors();

    List<Cursor> listOfCursors = cursorTestObserver.values();

    assertThat(listOfCursors).hasSize(1);

    Assertions.assertThat(listOfCursors.get(0)).hasCount(1);
    listOfCursors.get(0).moveToFirst();
    assertThat(testItemToInsert.equalsWithoutId(TestItem.fromCursor(listOfCursors.get(0))))
            .isTrue();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI));
}