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(); this.investmentsCount = original.getInvestmentsCount(); this.investmentRate = original.getInvestmentRate(); this.insuranceActive = original.isInsuranceActive(); this.published = original.isPublished(); this.questionsAllowed = original.isQuestionsAllowed(); this.topped = original.isTopped(); this.mainIncomeType = original.getMainIncomeType(); this.name = original.getName(); this.nickName = original.getNickName(); this.purpose = original.getPurpose(); this.questionsCount = original.getQuestionsCount(); this.rating = original.getRating(); this.region = original.getRegion(); this.remainingInvestment = (int) original.getRemainingInvestment(); this.nonReservedRemainingInvestment = (int) (original.getRemainingInvestment() - original.getReservedAmount()); this.story = original.getStory(); this.termInMonths = original.getTermInMonths(); this.userId = original.getUserId(); this.myInvestment = original.getMyInvestment(); this.url = Util.getUrlSafe(original); setInsuranceHistory(original.getInsuranceHistory());
/** * 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 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); }
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); }
MutableLoanImpl(final RawLoan original) { super(original); final BorrowerRelatedInvestmentInfo i = original.getBorrowerRelatedInvestmentInfo(); if (i == null) { this.setKnownBorrowerNicknames(Collections.emptyList()); } else { this.remainingPrincipalToBorrower = i.getRemainingPrincipalToBorrower(); this.remainingPrincipalToLoan = i.getRemainingPrincipalToLoan(); this.totalPrincipalToBorrower = i.getTotalPrincipalToBorrower(); this.totalPrincipalToLoan = i.getTotalPrincipalToLoan(); this.setKnownBorrowerNicknames(i.getOtherBorrowerNicknames()); } }
@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(); }
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); }
@Test void hasWrongUrl() { final RawLoan mocked = mock(RawLoan.class); when(mocked.getUrl()).thenReturn("something"); assertThatThrownBy(() -> Util.getUrlSafe(mocked)).isInstanceOf(IllegalStateException.class); } }
MutableLoanImpl(final RawLoan original) { super(original); final BorrowerRelatedInvestmentInfo i = original.getBorrowerRelatedInvestmentInfo(); if (i == null) { this.setKnownBorrowerNicknames(Collections.emptyList()); } else { this.remainingPrincipalToBorrower = i.getRemainingPrincipalToBorrower(); this.remainingPrincipalToLoan = i.getRemainingPrincipalToLoan(); this.totalPrincipalToBorrower = i.getTotalPrincipalToBorrower(); this.totalPrincipalToLoan = i.getTotalPrincipalToLoan(); this.setKnownBorrowerNicknames(i.getOtherBorrowerNicknames()); } }
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(); this.investmentsCount = original.getInvestmentsCount(); this.investmentRate = original.getInvestmentRate(); this.insuranceActive = original.isInsuranceActive(); this.published = original.isPublished(); this.questionsAllowed = original.isQuestionsAllowed(); this.topped = original.isTopped(); this.mainIncomeType = original.getMainIncomeType(); this.name = original.getName(); this.nickName = original.getNickName(); this.purpose = original.getPurpose(); this.questionsCount = original.getQuestionsCount(); this.rating = original.getRating(); this.region = original.getRegion(); this.remainingInvestment = (int) original.getRemainingInvestment(); this.nonReservedRemainingInvestment = (int)(original.getRemainingInvestment() - original.getReservedAmount()); this.story = original.getStory(); this.termInMonths = original.getTermInMonths(); this.userId = original.getUserId(); this.myInvestment = original.getMyInvestment(); this.url = Util.getUrlSafe(original); setInsuranceHistory(original.getInsuranceHistory());
/** * 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 + "/"); }