public Optional<RecommendedInvestment> recommend() { return recommend(getRemainingPrincipal()); }
public InvestmentWrapper(final InvestmentDescriptor original) { super(original); this.investment = original.item(); }
@Test void recommend() { final BigDecimal remainingPrincipal = BigDecimal.TEN; final Investment i = mockInvestment(remainingPrincipal); final InvestmentDescriptor id = new InvestmentDescriptor(i, () -> LOAN); final Optional<RecommendedInvestment> r = id.recommend(); assertThat(r).isPresent(); assertSoftly(softly -> { softly.assertThat(r.get().amount()).isEqualTo(remainingPrincipal); softly.assertThat(r.get().descriptor()).isEqualTo(id); softly.assertThat(r.get().descriptor().related()).isSameAs(LOAN); }); }
private static InvestmentDescriptor getDescriptor(final Investment i, final Tenant tenant) { return new InvestmentDescriptor(i, () -> LoanCache.get().getLoan(i, tenant)); }
@Test void recommendWrong() { final BigDecimal remainingPrincipal = BigDecimal.TEN; final Investment i = mockInvestment(remainingPrincipal); final InvestmentDescriptor id = new InvestmentDescriptor(i, () -> LOAN); final Optional<RecommendedInvestment> r = id.recommend(remainingPrincipal.subtract(BigDecimal.ONE)); assertThat(r).isEmpty(); }
private static Optional<Investment> processSale(final PowerTenant tenant, final RecommendedInvestment r, final SessionState<Investment> sold) { tenant.fire(EventFactory.saleRequested(r)); final Investment i = r.descriptor().item(); final boolean isRealRun = !tenant.getSessionInfo().isDryRun(); LOGGER.debug("Will send sell request for loan #{}: {}.", i.getLoanId(), isRealRun); if (isRealRun) { tenant.run(z -> z.sell(i)); LOGGER.info("Offered to sell investment in loan #{}.", i.getLoanId()); } sold.put(i); // make sure dry run never tries to sell this again in this instance tenant.fire(EventFactory.saleOffered(i, r.descriptor().related())); return Optional.of(i); }
@Override public Optional<RecommendedInvestment> recommend(final BigDecimal amount) { if (Objects.equals(amount, getRemainingPrincipal())) { return Optional.of(new RecommendedInvestment(this, amount)); } else { return Optional.empty(); } }
private static InvestmentDescriptor getDescriptor(final Investment i, final Tenant tenant) { return new InvestmentDescriptor(i, () -> tenant.getLoan(i.getLoanId())); }
private static RecommendedInvestment recommendedInvestment() { return new InvestmentDescriptor(Investment.custom().setRemainingPrincipal(BigDecimal.TEN).build(), () -> Loan.custom().build()).recommend().orElse(null); }
private static Optional<Investment> processSale(final PowerTenant tenant, final RecommendedInvestment r, final SessionState<Investment> sold) { tenant.fire(EventFactory.saleRequested(r)); final Investment i = r.descriptor().item(); final boolean isRealRun = !tenant.getSessionInfo().isDryRun(); LOGGER.debug("Will send sell request for loan #{}: {}.", i.getLoanId(), isRealRun); if (isRealRun) { tenant.run(z -> z.sell(i)); LOGGER.info("Offered to sell investment in loan #{}.", i.getLoanId()); } sold.put(i); // make sure dry run never tries to sell this again in this instance tenant.fire(EventFactory.saleOffered(i, r.descriptor().related())); return Optional.of(i); }
@Override public Optional<RecommendedInvestment> recommend(final BigDecimal amount) { if (Objects.equals(amount, getRemainingPrincipal())) { return Optional.of(new RecommendedInvestment(this, amount)); } else { return Optional.empty(); } }
@Test void equals() { final Investment i = mockInvestment(BigDecimal.TEN); final InvestmentDescriptor id = new InvestmentDescriptor(i, () -> LOAN); assertSoftly(softly -> { softly.assertThat(id).isNotEqualTo(null); softly.assertThat(id).isNotEqualTo(UUID.randomUUID().toString()); softly.assertThat(id).isEqualTo(id); }); final InvestmentDescriptor id2 = new InvestmentDescriptor(i, () -> LOAN); assertSoftly(softly -> { softly.assertThat(id).isEqualTo(id2); softly.assertThat(id2).isEqualTo(id); }); final InvestmentDescriptor id3 = new InvestmentDescriptor(mockInvestment(BigDecimal.ONE), () -> LOAN); assertThat(id).isNotEqualTo(id3); } }
public Optional<RecommendedInvestment> recommend() { return recommend(getRemainingPrincipal()); }
public InvestmentWrapper(final InvestmentDescriptor original) { super(original); this.investment = original.item(); }
@Test void equals() { final BigDecimal remainingPrincipal = BigDecimal.TEN; final Investment i = mockInvestment(remainingPrincipal); final InvestmentDescriptor d = new InvestmentDescriptor(i, () -> LOAN); final RecommendedInvestment r = new RecommendedInvestment(d, remainingPrincipal); assertSoftly(softly -> { softly.assertThat(r).isNotEqualTo(null); softly.assertThat(r).isNotEqualTo(UUID.randomUUID().toString()); softly.assertThat(r).isEqualTo(r); }); final RecommendedInvestment r2 = new RecommendedInvestment(d, remainingPrincipal); assertSoftly(softly -> { softly.assertThat(r).isEqualTo(r2); softly.assertThat(r2).isEqualTo(r); }); final RecommendedInvestment r3 = new RecommendedInvestment(new InvestmentDescriptor(mockInvestment(remainingPrincipal), () -> LOAN), remainingPrincipal); assertThat(r).isNotEqualTo(r3); } }
@Test void equality() { final InvestmentDescriptor original = new InvestmentDescriptor(INVESTMENT, () -> LOAN); final Wrapper<InvestmentDescriptor> w = Wrapper.wrap(original); assertSoftly(softly -> { softly.assertThat(w).isEqualTo(w); softly.assertThat(w).isEqualTo(Wrapper.wrap(original)); softly.assertThat(w).isEqualTo(Wrapper.wrap(new InvestmentDescriptor(INVESTMENT, () -> LOAN))); softly.assertThat(w).isNotEqualTo(null); }); } }
@Test void sellOffStarted() { final DefaultPortfolio portfolio = DefaultPortfolio.EMPTY; final DefaultValues values = new DefaultValues(portfolio); // activate default sell-off 3 months before the given date, which is already in the past values.setExitProperties(new ExitProperties(LocalDate.now().plusMonths(2))); final ParsedStrategy strategy = new ParsedStrategy(values, Collections.emptyList()); // no loan or participation should be bought; every investment should be sold final Loan l = ParsedStrategyTest.mockLoan(1000); final LoanDescriptor ld = new LoanDescriptor(l); final ParticipationDescriptor pd = ParsedStrategyTest.mockParticipationDescriptor(l); final Investment i = Investment.fresh(l, 200); final InvestmentDescriptor id = new InvestmentDescriptor(i, () -> l); assertSoftly(softly -> { softly.assertThat(strategy.getApplicableLoans(Collections.singleton(ld))).isEmpty(); softly.assertThat(strategy.getApplicableParticipations(Collections.singleton(pd))).isEmpty(); softly.assertThat(strategy.getApplicableInvestments(Collections.singleton(id))).containsOnly(id); }); }
final ParticipationDescriptor pdUnder = ParsedStrategyTest.mockParticipationDescriptor(loanUnder); final Investment iUnder = Investment.fresh(loanUnder, 200); final InvestmentDescriptor idUnder = new InvestmentDescriptor(iUnder, () -> loanUnder); final Investment iOver = Investment.fresh(loanOver, 200); final InvestmentDescriptor idOver = new InvestmentDescriptor(iOver, () -> loanOver); assertSoftly(softly -> { softly.assertThat(strategy.getApplicableLoans(Arrays.asList(ldOver, ldUnder))).containsOnly(ldUnder);
@Test void values() { final InvestmentDescriptor original = new InvestmentDescriptor(INVESTMENT, () -> LOAN); final Wrapper<InvestmentDescriptor> w = Wrapper.wrap(original); assertSoftly(softly -> { softly.assertThat(w.isInsuranceActive()).isEqualTo(INVESTMENT.isInsuranceActive()); softly.assertThat(w.getInterestRate()).isEqualTo(INVESTMENT.getInterestRate()); softly.assertThat(w.getRegion()).isEqualTo(LOAN.getRegion()); softly.assertThat(w.getRating()).isEqualTo(INVESTMENT.getRating()); softly.assertThat(w.getMainIncomeType()).isEqualTo(LOAN.getMainIncomeType()); softly.assertThat(w.getPurpose()).isEqualTo(LOAN.getPurpose()); softly.assertThat(w.getOriginalAmount()).isEqualTo(LOAN.getAmount()); softly.assertThat(w.getRemainingPrincipal()).isEqualTo(INVESTMENT.getRemainingPrincipal()); softly.assertThat(w.getOriginal()).isSameAs(original); softly.assertThat(w.getStory()).isEqualTo(LOAN.getStory()); softly.assertThat(w.getOriginalTermInMonths()).isEqualTo(INVESTMENT.getOriginalTerm()); softly.assertThat(w.getRemainingTermInMonths()).isEqualTo(INVESTMENT.getRemainingMonths()); softly.assertThat(w.toString()).isNotNull(); }); }