PrimaryMarketplaceAccessor extends AbstractMarketplaceAccessor<LoanDescriptor> { @Override public Collection<LoanDescriptor> getMarketplace() { Stream<Loan> loans = tenant.call(zonky -> zonky.getAvailableLoans(getIncrementalFilter())) .filter(l -> l.getMyInvestment() .isEmpty()); if (getMaximumItemsToRead().isPresent()) { int limit = getMaximumItemsToRead().orElseThrow(); LOGGER.trace("Enforcing read limit of {} latest items.", limit); loans = loans.limit(limit); } return loans.map(LoanDescriptor::new) .collect(Collectors.toList()); } PrimaryMarketplaceAccessor(final Tenant tenant, final UnaryOperator<LastPublishedItem> stateAccessor); @Override Duration getForcedMarketplaceCheckInterval(); @Override Collection<LoanDescriptor> getMarketplace(); @Override boolean hasUpdates();  }
@Test void eliminatesUselessLoans() { final Loan alreadyInvested = new MockLoanBuilder() .set(LoanImpl::setRating, Rating.B) .set(LoanImpl::setRemainingInvestment, Money.from(1)) .set(LoanImpl::setReservedAmount, Money.from(0)) .set(LoanImpl::setMyInvestment, mockMyInvestment()) .build(); final Loan normal = new MockLoanBuilder() .set(LoanImpl::setRating, Rating.A) .set(LoanImpl::setRemainingInvestment, Money.from(1)) .set(LoanImpl::setReservedAmount, Money.from(0)) .build(); final Zonky zonky = harmlessZonky(); when(zonky.getAvailableLoans(any())).thenReturn(Stream.of(alreadyInvested, normal)); final Tenant tenant = mockTenant(zonky); final AbstractMarketplaceAccessor<LoanDescriptor> d = new PrimaryMarketplaceAccessor(tenant, UnaryOperator.identity()); final Collection<LoanDescriptor> ld = d.getMarketplace(); assertThat(ld).hasSize(1) .element(0) .extracting(LoanDescriptor::item) .isSameAs(normal); }