PortofolioService { public Portofolio getPortofolio(String login) { PortofolioEntity portofolio = portofolioRepo.findByUserUsername(login); AssetInfo baseCurrencyAsset = new AssetInfo(portofolio.getBaseCurrency(), null, portofolio.getAmount().doubleValue()); List<AssetInfo> assets = new ArrayList<>(); double globalBaseCurrencyValueChange = 0f; double globalBaseCurrencyInvestedValue = 0f; for (AssetEntity ae : portofolio.getAssets()) { AssetInfo asset = getAsset(ae); String currencyCode = asset.getCurrency().getCode(); BigDecimal assetCurrencyToBaseCurrencyRate = rateService.getLatest(currencyCode, portofolio.getBaseCurrency().getCode()).getValue(); BigDecimal baseCurrencyValueChange = assetCurrencyToBaseCurrencyRate.multiply(BigDecimal.valueOf(asset.getValueChange())); BigDecimal baseCurrencyInvestedValue = assetCurrencyToBaseCurrencyRate.multiply(BigDecimal.valueOf(asset.getValue())); globalBaseCurrencyValueChange += baseCurrencyValueChange.doubleValue(); globalBaseCurrencyInvestedValue += baseCurrencyInvestedValue.doubleValue(); assets.add(asset); } double globalPercentChange = 0; if (globalBaseCurrencyInvestedValue != 0) { globalPercentChange = globalBaseCurrencyValueChange / globalBaseCurrencyInvestedValue * 100d; } double globalBaseCurrencyValue = globalBaseCurrencyInvestedValue + globalBaseCurrencyValueChange; return new Portofolio(baseCurrencyAsset, assets, globalBaseCurrencyValue, globalPercentChange, globalBaseCurrencyValueChange); }  Portofolio createPortofolio(String login, String baseCurrencyCode, int baseCurrencyAmount); AssetInfo getBaseCurrency(String login); Portofolio getPortofolio(String login); OrderInfo getOrderInfo(String login, String symbolCode, double quantity); List<Symbol> getAvailableSymbols(String login); Order buy(String login, String code, double quantity); Order sell(String login, String code, double quantity);  }
@Test public void testGetPortofolio() { String login = "user"; Portofolio result = portofolioService.getPortofolio(login); assertThat(result.getPercentChange()).isCloseTo(13.47978618287961, PERCENT_OFFSET); assertThat(result.getValueChange()).isCloseTo(922.8690277999999, PERCENT_OFFSET); assertThat(result.getAssets()).extracting("symbol.code", "percentChange", "valueChange") .containsExactlyInAnyOrder( tuple("UBI", -6.14999667, -184.4999), tuple("BRE", 39.33333333, 1180d), tuple("GBP", 5.54032065, 66.4838478)); }