SelectAddressPresenter extends BasePresenter<SelectAddressContract.View> implements SelectAddressContract.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 selectAddress(int position);  }
@Test public void testFetchAddressList() { List<AddressEntity> entityList = new ArrayList<>(); AddressEntity entity = new AddressEntity(); entity.setAddress("0x15asd35f5ad5fa34s5df4as53"); entity.setAvatar(""); entity.setName("qianbao-1"); entity.setUuid(UUID.randomUUID().toString()); entityList.add(entity); AddressEntity entity2 = new AddressEntity(); entity2.setAddress("0x15asd35f5ad5fa34s5df4as53"); entity2.setAvatar(""); entity2.setName("qianbao-2"); entity2.setUuid(UUID.randomUUID().toString()); entityList.add(entity2); AddressEntity entity3 = new AddressEntity(); entity3.setAddress("0x15asd35f5ad5fa34s5df4as53"); entity3.setAvatar(""); entity3.setName("qianbao-3"); entity3.setUuid(UUID.randomUUID().toString()); entityList.add(entity3); AddressEntity entity4 = new AddressEntity(); entity4.setAddress("0x15asd35f5ad5fa34s5df4as53"); entity4.setAvatar(""); entity4.setName("qianbao-4"); entity4.setUuid(UUID.randomUUID().toString()); entityList.add(entity4); 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() .subscribe(new BiConsumer<List<Address>, Throwable>() { @Override public void accept(List<Address> addressEntities, Throwable throwable) throws Exception { assertNotNull(addressEntities); for (Address address : addressEntities) { System.out.println(address.getUuid() + "===============" + address.getName()); } } }); }