DatabaseService implements LocalService { @Override public Observable<User> getUser(String id) { return Observable.create((Observable.OnSubscribe<User>) subscriber -> { try { User user = SQLite.select().from(CacheUser.class).where(CacheUser_Table.id.eq(id)).querySingle(); if (user == null) { RxUtils.onError(subscriber, new DataNotFoundException()); } else { RxUtils.onNext(subscriber, user, 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 testGetUser() throws Exception { TestSubscriber<User> testSubscriber = new TestSubscriber<>(); CacheUser cacheUser = new CacheUser("1", "Lam", "lam@mysquar.com", "Lam", "123", "http: mDatabaseService.saveUser(cacheUser) .flatMap(aVoid -> mDatabaseService.getUser(cacheUser.getId())) .subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<User> users = testSubscriber.getOnNextEvents(); User user = users.get(0); assertThat(user, notNullValue()); assertThat(user.getId(), equalTo(cacheUser.getId())); assertThat(user.getCoverUrl(), equalTo(cacheUser.getCoverUrl())); assertThat(user.getDescription(), equalTo(cacheUser.getDescription())); assertThat(user.getEmail(), equalTo(cacheUser.getEmail())); assertThat(user.getFollowers(), equalTo(cacheUser.getFollowers())); assertThat(user.getFullName(), equalTo(cacheUser.getFullName())); }