private String getMostFunded(List<Object[]> objects) { return objects .stream() .collect(Collectors.groupingBy(o -> (String) o[0], Collectors.reducing(0.0, o -> mapToUsd(new TokenAmountDto((String) o[1], (BigDecimal) o[2])), (a, b) -> a + b) ) ) .entrySet().stream().max(Comparator.comparing(Map.Entry::getValue)) .map(Map.Entry::getKey).orElse(""); }
@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); }
@Test public void statisticsReturnsMostFundedProject() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); List<Object[]> requests = Arrays.asList( createObject("FundRequest", fnd.getAddress(), tokenAmount.getTotalAmount()), createObject("Dock", zrx.getAddress(), tokenAmount2.getTotalAmount()) ); when(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()).thenReturn(requests); 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.getMostFundedProject()).isEqualTo("Dock"); }
@Test public void statisticsReturnsMostFundedTechnology() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); List<Object[]> requests = Arrays.asList( createObject("Java", fnd.getAddress(), tokenAmount.getTotalAmount()), createObject("Python", zrx.getAddress(), tokenAmount2.getTotalAmount()) ); when(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()).thenReturn(requests); 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.getMostFundedTechnology()).isEqualTo("Python"); }