@Test public void findAll() { List<Fund> funds = singletonList(FundMother.fndFundFunderKnown().build()); when(fundRepository.findAll()).thenReturn(funds); List<FundDto> expecedFunds = singletonList(FundDtoMother.aFundDto().build()); when(mappers.mapList(Fund.class, FundDto.class, funds)).thenReturn(expecedFunds); List<FundDto> result = fundService.findAll(); assertThat(result).isEqualTo(expecedFunds); }
@Test public void saveFunds() { final Request request = RequestMother.freeCodeCampNoUserStories().build(); final FundsAddedCommand command = FundsAddedCommand.builder() .requestId(request.getId()) .amountInWei(BigDecimal.TEN) .blockchainEventId(465L) .transactionHash("trans_hash") .funderAddress("address") .timestamp(LocalDateTime.now()) .token("token") .build(); final FundDto fundDto = FundDtoMother.aFundDto().build(); final RequestDto requestDto = new RequestDto(); final Cache cache = mock(Cache.class); when(requestRepository.findOne(request.getId())).thenReturn(Optional.of(request)); when(mappers.map(eq(Fund.class), eq(FundDto.class), any(Fund.class))).thenReturn(fundDto); when(mappers.map(eq(Request.class), eq(RequestDto.class), any(Request.class))).thenReturn(requestDto); when(cacheManager.getCache("funds")).thenReturn(cache); when(pendingFundRepository.findByTransactionHash(command.getTransactionHash())).thenReturn(Optional.of(PendingFund.builder().userId(funder.getName()).build())); fundService.addFunds(command); verifyFundsSaved(command, funder); verifyEventCreated(request.getId(), fundDto); verify(cache).evict(request.getId()); }
@Test public void onFunded() { final RequestFundedEvent fundedEvent = RequestFundedEvent.builder() .fundDto(FundDtoMother.aFundDto().build()) .timestamp(LocalDateTime.now()) .requestId(35L).build(); final RequestFundedNotificationDto expected = RequestFundedNotificationDto.builder() .blockchainEventId(fundedEvent.getFundDto().getBlockchainEventId()) .date(fundedEvent.getTimestamp()) .requestId(fundedEvent.getRequestId()) .fundId(fundedEvent.getFundDto().getId()) .build(); eventHandler.onFunded(fundedEvent); verify(applicationEventPublisher).publishEvent(refEq(expected, "uuid")); } }
public static FundDto.FundDtoBuilder aFundDto() { final TokenInfoDto fnd = TokenInfoDtoMother.fnd(); return FundDto.builder() .tokenValue(TokenValueDto.builder() .totalAmount(new BigDecimal("3.870000000000000000")) .tokenAddress(fnd.getAddress()) .tokenSymbol(fnd.getSymbol()) .build()) .blockchainEventId(3465L) .funderAddress("0xd24400ae8BfEBb18cA49Be86258a3C749cf46853") .requestId(1L) .timestamp(LocalDateTime.of(2017, Month.DECEMBER, 27, 0, 0)); } }
@Test public void findAllByIterable() { List<Fund> funds = singletonList(FundMother.fndFundFunderKnown().build()); Set<Long> ids = funds.stream().map(Fund::getId).collect(Collectors.toSet()); when(fundRepository.findAll(ids)).thenReturn(funds); List<FundDto> expecedFunds = singletonList(FundDtoMother.aFundDto().build()); when(mappers.mapList(Fund.class, FundDto.class, funds)).thenReturn(expecedFunds); List<FundDto> result = fundService.findAll(ids); assertThat(result).isEqualTo(expecedFunds); }