@Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") public StatisticsDto getStatistics() { double totalAvailableFunding = fundRepository.getAmountPerTokenWhereRequestHasStatusFunded() .stream() .mapToDouble(this::mapToUsd) .sum(); String mostFundedProject = getMostFunded(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()); String mostFundedTechnology = getMostFunded(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()); return StatisticsDto.builder() .totalAvailableFunding(totalAvailableFunding) .mostFundedProject(mostFundedProject) .mostFundedTechnology(mostFundedTechnology) .build(); }
@Test public void statisticsReturnsTotalAvailableFunding() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); when(fundRepository.getAmountPerTokenWhereRequestHasStatusFunded()).thenReturn(Arrays.asList(tokenAmount, tokenAmount2)); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getTotalAvailableFunding()).isEqualTo(30.0); }