AddressBookPresenter extends BasePresenter<AddressBookContract.View> implements AddressBookContract.Presenter { @Override public void fetchAddressList() { Flowable.fromIterable(AddressDao.getAddressInfoList()).filter(new Predicate<AddressEntity>() { @Override public boolean test(AddressEntity addressInfoEntity) throws Exception { return addressInfoEntity != null; } }).compose(((BaseActivity) getView()).bindToLifecycle()).map(new Function<AddressEntity, Address>() { @Override public Address apply(AddressEntity addressInfoEntity) throws Exception { return new Address(addressInfoEntity.getUuid(), addressInfoEntity.getName(),addressInfoEntity.getAddress(),addressInfoEntity.getAvatar()); } }).toList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BiConsumer<List<Address>, Throwable>() { @Override public void accept(List<Address> addressEntities, Throwable throwable) throws Exception { addressEntityList = addressEntities; if (isViewAttached()) { getView().notifyAddressListChanged(addressEntities); } } }); }  List<Address> getAddressEntityList(); void setAddressEntityList(List<Address> addressEntityList); @Override void fetchAddressList(); @Override void deleteAddress(int position); @Override void editAddress(int position); @Override void selectAddress(int position);  }
@Test public void testFetchAddressList() { List<Address> list = Flowable.fromIterable(entityList).filter(new Predicate<AddressEntity>() { @Override public boolean test(AddressEntity addressInfoEntity) throws Exception { return addressInfoEntity != null; } }).map(new Function<AddressEntity, Address>() { @Override public Address apply(AddressEntity addressInfoEntity) throws Exception { return new Address(addressInfoEntity.getUuid(), addressInfoEntity.getName(), addressInfoEntity.getAddress(), addressInfoEntity.getAvatar()); } }).toList().blockingGet(); assertNotNull(list); for(Address address :list){ System.out.println(address.getUuid() + "=====================" +address.getName()); } }