DatabaseService implements LocalService { @Override public Observable<List<? extends User>> getUsers() { return Observable.create(subscriber -> { try { List<CacheUser> cacheUsers = SQLite.select().from(CacheUser.class).queryList(); RxUtils.onNext(subscriber, cacheUsers, true); } catch (Exception e) { RxUtils.onError(subscriber, e); } }); } DatabaseService(MVVMConverter<User, CacheUser> userConverter); @Override Observable<User> observeLocalChange(); @Override Observable<User> getUser(String id); @Override Observable<List<? extends User>> getUsers(); @Override Observable<Void> saveUser(User user); @Override Observable<Void> saveUsers(List<User> users); @Override Observable<Void> removeUser(String id); @Override Observable<Void> removeUsers(List<String> ids);  }
@Test public void testGetUsers() throws Exception { List<User> cacheUsers = new ArrayList<>(); cacheUsers.add(new CacheUser("1", "Lam", "lam@mysquar.com", "Lam", "123", "http: cacheUsers.add(new CacheUser("2", "Henry", "henry@mysquar.com", "Henry", "456", "http: cacheUsers.add(new CacheUser("3", "Long", "long@mysquar.com", "Long", "789", "http: mDatabaseService.saveUsers(cacheUsers).subscribe(); TestSubscriber<List<? extends User>> testSubscriber = new TestSubscriber<>(); mDatabaseService.getUsers().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<? extends User> users = testSubscriber.getOnNextEvents().get(0); assertThat(users.size(), equalTo(cacheUsers.size())); for (int i = 0; i < users.size(); i++) { assertThat(users.get(i).getId(), equalTo(cacheUsers.get(i).getId())); assertThat(users.get(i).getCoverUrl(), equalTo(cacheUsers.get(i).getCoverUrl())); assertThat(users.get(i).getDescription(), equalTo(cacheUsers.get(i).getDescription())); assertThat(users.get(i).getEmail(), equalTo(cacheUsers.get(i).getEmail())); assertThat(users.get(i).getFollowers(), equalTo(cacheUsers.get(i).getFollowers())); assertThat(users.get(i).getFullName(), equalTo(cacheUsers.get(i).getFullName())); } }