BookServiceImpl implements BookService { @Override public Observable<List<FireBookDetails>> getBooksForLanguage(final FireLanguage language) { return bookDatabase.getBooks().flatMap(filterEnabledBooks()).flatMap(filterLanguage(language)); } BookServiceImpl(BookDatabase bookDatabase); @Override Observable<List<FireLanguage>> getLanguages(); @Override Observable<List<FireBookDetails>> getBooksForLanguage(final FireLanguage language); @Override Observable<List<FireContributor>> getContributorsForBook(final FireBookDetails book); @Override Observable<List<FireBookDetails>> getDownloadedBooks(); @Override Observable<List<FireBookDetails>> searchBooks(final String searchTerm);  }
@Test public void testGetBooksForLanguage() throws Exception { FireLanguage fireLanguage = new FireLanguage("English", "en", true, "123"); FireBookDetails fireBookDetails = new FireBookDetails("Book Title", "url", "cover_url", true, "test description", fireLanguage, System.currentTimeMillis()); ArrayList<FireBookDetails> bookDetails = new ArrayList<>(); bookDetails.add(fireBookDetails); doReturn(Observable.<List<FireBookDetails>>just(bookDetails)).when(bookDatabase).getBooks(); TestSubscriber<List<FireBookDetails>> testSubscriber = new TestSubscriber<>(); bookService.getBooksForLanguage(fireLanguage).subscribe(testSubscriber); verify(bookDatabase).getBooks(); testSubscriber.awaitTerminalEvent(); testSubscriber.assertNoErrors(); final List<List<FireBookDetails>> result = testSubscriber.getOnNextEvents(); assertEquals("Book Title", result.get(0).get(0).getBookTitle()); }