private static boolean notifyProvider(final RawLoan loan, final ConfirmationProvider zonkoid, final String username, final char... secret) { final RequestId id = new RequestId(username, secret); return zonkoid.requestConfirmation(id, loan.getId(), 200); }
private static boolean notifyProvider(final RawLoan loan, final ConfirmationProvider zonkoid, final String username, final char... secret) { final RequestId id = new RequestId(username, secret); return zonkoid.requestConfirmation(id, loan.getId(), 200); }
/** * Zonky's API documentation states that {@link RawLoan#getUrl()} is optional. Therefore the only safe use of that * attribute is through this method. * @return URL to a loan on Zonky's website. Guessed if not present. */ static URL getUrlSafe(final RawLoan l) { // in case investment has no loan, we guess loan URL final String providedUrl = l.getUrl(); if (providedUrl == null) { return guessUrl(l.getId()); } else { return toUrl(providedUrl); } }
/** * Zonky's API documentation states that {@link RawLoan#getUrl()} is optional. Therefore the only safe use of that * attribute is through this method. * @return URL to a loan on Zonky's website. Guessed if not present. */ static URL getUrlSafe(final RawLoan l) { // in case investment has no loan, we guess loan URL final String providedUrl = l.getUrl(); if (providedUrl == null) { return guessUrl(l.getId()); } else { return toUrl(providedUrl); } }
@Test void guessesUrl() { final int id = 1; final RawLoan mocked = mock(RawLoan.class); when(mocked.getId()).thenReturn(id); assertThat(Util.getUrlSafe(mocked).toString()).isEqualTo( "https://app.zonky.cz/#/marketplace/detail/" + id + "/"); }
@Test void loan() { final PaginatedApi<RawLoan, LoanApi> la = mockApi(); final int loanId = 1; final RawLoan loan = mock(RawLoan.class); when(loan.getId()).thenReturn(loanId); when(loan.getAmount()).thenReturn(200.0); when(loan.getRemainingInvestment()).thenReturn(200.0); when(la.execute(any())).thenReturn(loan); final ApiProvider p = spy(new ApiProvider()); when(p.marketplace(any())).thenReturn(la); final Zonky z = new Zonky(p, () -> mock(ZonkyApiToken.class)); assertThat(z.getLoan(loanId).getId()).isEqualTo(loanId); }
@Test void investAndlogout() { final ControlApi control = mock(ControlApi.class); final Api<ControlApi> ca = mockApi(control); final PaginatedApi<RawLoan, LoanApi> la = mockApi(); final int loanId = 1; final RawLoan loan = mock(RawLoan.class); when(loan.getId()).thenReturn(loanId); when(loan.getAmount()).thenReturn(200.0); when(loan.getRemainingInvestment()).thenReturn(200.0); when(la.execute(any())).thenReturn(loan); final Zonky z = mockZonky(ca, la); final Loan l = z.getLoan(loanId); final Investment i = Investment.fresh(l, 200); z.invest(i); z.logout(); verify(control, times(1)).invest(any()); verify(control, times(1)).logout(); }
AbstractMutableLoanImpl(final RawLoan original) { LOGGER.trace("Sanitizing loan #{}.", original.getId()); this.activeLoansCount = original.getActiveLoansCount(); this.amount = (int) original.getAmount(); this.datePublished = original.getDatePublished(); this.deadline = original.getDeadline(); this.id = original.getId(); this.covered = original.isCovered(); this.interestRate = original.getInterestRate();
AbstractMutableLoanImpl(final RawLoan original) { LOGGER.trace("Sanitizing loan #{}.", original.getId()); this.activeLoansCount = original.getActiveLoansCount(); this.amount = (int) original.getAmount(); this.datePublished = original.getDatePublished(); this.deadline = original.getDeadline(); this.id = original.getId(); this.covered = original.isCovered(); this.interestRate = original.getInterestRate();