use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class LoanCacheTest method emptyGetLoan.
@Test
void emptyGetLoan() {
final LoanCache c = new LoanCache();
final int loanId = 1;
// nothing returned at first
assertThat(c.getLoan(loanId)).isEmpty();
final MyInvestment mi = mock(MyInvestment.class);
when(mi.getTimeCreated()).thenReturn(OffsetDateTime.now());
final Loan loan = Loan.custom().setId(loanId).setMyInvestment(mi).build();
final Zonky z = harmlessZonky(10_000);
when(z.getLoan(eq(loanId))).thenReturn(loan);
// return the freshly retrieved loan
assertThat(c.getLoan(loanId, z)).isEqualTo(loan);
final Investment i = Investment.custom().setLoanId(loanId).build();
assertThat(c.getLoan(i, z)).isEqualTo(loan);
assertThat(i.getInvestmentDate()).isNotEmpty();
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class StrategyExecutorTest method rechecksMarketplaceIfFirstCheckFailed.
@Test
void rechecksMarketplaceIfFirstCheckFailed() {
final Zonky zonky = harmlessZonky(10_000);
final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
final Loan loan = Loan.custom().build();
final LoanDescriptor ld = new LoanDescriptor(loan);
final Collection<LoanDescriptor> marketplace = Collections.singleton(ld);
// prepare the executor, have it fail when executing the investment operation
final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = new AlwaysFreshNeverInvesting();
final StrategyExecutor<LoanDescriptor, InvestmentStrategy> mocked = spy(e);
doThrow(new IllegalStateException()).when(mocked).execute(any(), any(), any());
Assertions.assertThatThrownBy(() -> mocked.apply(p, marketplace)).isInstanceOf(IllegalStateException.class);
// now the method won't throw, but must be executed again
reset(mocked);
mocked.apply(p, marketplace);
verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
// marketplace stays the same + balance stays the same+ previous update passed = no update should be triggered
reset(mocked);
when(mocked.hasMarketplaceUpdates(eq(marketplace))).thenReturn(false);
mocked.apply(p, marketplace);
verify(mocked, never()).execute(any(), any(), any());
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class LoanCache method getLoan.
public Loan getLoan(final int loanId, final Zonky api) {
return getLoan(loanId).orElseGet(() -> {
final Loan l = api.getLoan(loanId);
addLoan(loanId, l);
return l;
});
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class InvestmentSizeRecommenderTest method minimumOverBalance.
@Test
void minimumOverBalance() {
final Loan l = mockLoan(100_000);
final ParsedStrategy s = mock(ParsedStrategy.class);
final int minimumInvestment = 1000;
when(s.getMinimumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment);
when(s.getMaximumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment * 2);
when(s.getMaximumInvestmentShareInPercent()).thenReturn(100);
final BiFunction<Loan, Integer, Integer> r = new InvestmentSizeRecommender(s, minimumInvestment * 10);
assertThat(r.apply(l, minimumInvestment - 1)).isEqualTo(0);
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class InvestmentSizeRecommenderTest method nothingMoreToInvest.
@Test
void nothingMoreToInvest() {
final ParsedStrategy s = getStrategy();
final Loan l = mockLoan(Defaults.MINIMUM_INVESTMENT_IN_CZK - 1);
final InvestmentSizeRecommender r = new InvestmentSizeRecommender(s, Defaults.MAXIMUM_INVESTMENT_IN_CZK);
// with unlimited balance, make maximum possible recommendation
final int actualInvestment = r.apply(l, Integer.MAX_VALUE);
assertThat(actualInvestment).isEqualTo(0);
}
Aggregations