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

The following examples show how to use io.reactivex.observers.TestObserver#await() . 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: ModelsTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 6 votes vote down vote up
private void testMovieList(final IMovieCollection movies) throws InterruptedException {
    final ICollectionObserver collectionObserver = mock(ICollectionObserver.class);
    movies.addObserver(collectionObserver);

    assertNotNull("getMovies() should not return null!", movies.getMovies());
    assertFalse("isLoading should be false.", movies.isLoading());
    assertFalse("isLoaded should be false.", movies.isLoaded());
    final TestObserver<Void> testSubscriber = movies.load().test();
    testSubscriber.await();
    testSubscriber.assertNoErrors();

    assertFalse("isLoading should be false.", movies.isLoading());
    assertTrue("isLoaded should be true.", movies.isLoaded());
    assertFalse("hasNexPage should be false.", movies.hasNexPage());

    verify(collectionObserver).onUpdate(eq(movies), eq(Action.AppendRange), eq(null), anyList());

    final List<Movie> similarMoviesResult = movies.getMovies();
    assertNotNull("getMovies() should not return null after load()!", similarMoviesResult);
    verifyMovieList(similarMoviesResult);
}
 
Example 2
Source File: FavoriteMovieCollectionTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 6 votes vote down vote up
private void testMovieList(final IMovieCollection movies) throws InterruptedException {
    final ICollectionObserver collectionObserver = mock(ICollectionObserver.class);
    movies.addObserver(collectionObserver);

    assertNotNull("getMovies() should not return null!", movies.getMovies());
    assertFalse("isLoading should be false.", movies.isLoading());
    assertFalse("isLoaded should be false.", movies.isLoaded());
    final TestObserver<Void> testSubscriber = movies.load().test();
    testSubscriber.await();
    testSubscriber.assertNoErrors();

    assertFalse("isLoading should be false.", movies.isLoading());
    assertTrue("isLoaded should be true.", movies.isLoaded());
    assertFalse("hasNexPage should be false.", movies.hasNexPage());

    verify(collectionObserver).onUpdate(eq(movies), eq(Action.AppendItem), any(), eq(null));

    final List<Movie> similarMoviesResult = movies.getMovies();
    assertNotNull("getMovies() should not return null after load()!", similarMoviesResult);
    verifyMovieList(similarMoviesResult);
}
 
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: FavoriteMovieCollectionTest.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.NcssCount")
@Test
public void testAddFavoriteMovie() throws Exception {
    final IFavoriteStore favoriteStore = mock(IFavoriteStore.class);
    when(favoriteStore.addFavoriteMovie(any())).thenReturn(Single.just(true));

    final IFavoriteMovieCollection favorite = new FavoriteMovieCollection(favoriteStore, entityStore);

    final ICollectionObserver collectionObserver = mock(ICollectionObserver.class);
    favorite.addObserver(collectionObserver);

    final Movie movie = new Movie(service, entityStore, movie1Data);
    assertFalse("isFavorite should be false.", movie.isFavorite());
    assertNotNull("getMovies() should not return null!", favorite.getMovies());
    assertTrue("Favorite movie list should be empty.", favorite.getMovies().isEmpty());

    final IObserver objectObserver = mock(IObserver.class);
    movie.addObserver(objectObserver);

    final TestObserver<Boolean> testSubscriber = favorite.addToFavorite(movie).test();
    testSubscriber.await();
    testSubscriber.assertNoErrors();

    verify(favoriteStore).addFavoriteMovie(eq(movie1Data));
    verify(collectionObserver).onUpdate(eq(favorite), eq(Action.AddItemToFront), eq(movie), eq(null));
    verify(objectObserver).onUpdate(eq(movie), any());

    assertTrue("isFavorite should be false.", movie.isFavorite());
    assertEquals("Favorite movie list should contain exact one item.",
            1, favorite.getMovies().size());
    verifyMovie1(favorite.getMovies().get(0));
}