@Test void getPaidBounties() { Principal principal = () -> "davyvanroy"; Bounty bounty = Bounty.builder().type(BountyType.LINK_GITHUB).build(); ReflectionTestUtils.setField(bounty, "transactionHash", "0x0"); when(bountyRepository.findByUserId(principal.getName())).thenReturn(Collections.singletonList(bounty)); List<PaidBountyDto> result = bountyService.getPaidBounties(principal); assertThat(result).hasSize(1); }
@Override @Transactional(readOnly = true) public List<PaidBountyDto> getPaidBounties(Principal principal) { return bountyRepository.findByUserId(principal.getName()) .stream() .filter(f -> StringUtils.isNotBlank(f.getTransactionHash())) .sorted(Comparator.comparing(AbstractEntity::getCreationDate).reversed()) .map(b -> PaidBountyDto.builder() .type(b.getType()) .amount(b.getType().getReward()) .transactionHash(b.getTransactionHash()) .build() ) .collect(Collectors.toList()); }
BountyServiceImpl implements BountyService { @Override @Transactional(readOnly = true) public List<PaidBountyDto> getPaidBounties(Principal principal) { return bountyRepository.findByUserId(principal.getName()) .stream() .filter(f -> StringUtils.isNotBlank(f.getTransactionHash())) .sorted(Comparator.comparing(AbstractEntity::getCreationDate).reversed()) .map(b -> PaidBountyDto.builder() .type(b.getType()) .amount(b.getType().getReward()) .transactionHash(b.getTransactionHash()) .build() ) .collect(Collectors.toList()); } }
BountyServiceImpl implements BountyService { @Override @Transactional(readOnly = true) public List<PaidBountyDto> getPaidBounties(Principal principal) { return bountyRepository.findByUserId(principal.getName()) .stream() .filter(f -> StringUtils.isNotBlank(f.getTransactionHash())) .sorted(Comparator.comparing(AbstractEntity::getCreationDate).reversed()) .map(b -> PaidBountyDto.builder() .type(b.getType()) .amount(b.getType().getReward()) .transactionHash(b.getTransactionHash()) .build() ) .collect(Collectors.toList()); } BountyServiceImpl(BountyRepository bountyRepository); }
BountyServiceImpl implements BountyService { @Override @Transactional(readOnly = true) public List<PaidBountyDto> getPaidBounties(Principal principal) { return bountyRepository.findByUserId(principal.getName()) .stream() .filter(f -> StringUtils.isNotBlank(f.getTransactionHash())) .sorted(Comparator.comparing(AbstractEntity::getCreationDate).reversed()) .map(b -> PaidBountyDto.builder() .type(b.getType()) .amount(b.getType().getReward()) .transactionHash(b.getTransactionHash()) .build() ) .collect(Collectors.toList()); } BountyServiceImpl(BountyRepository bountyRepository); @Transactional @Override void createBounty(CreateBountyCommand createBountyCommand); @Override BountyDTO getBounties(final Principal principal); @Override @Transactional(readOnly = true) List<PaidBountyDto> getPaidBounties(Principal principal); }
BountyServiceImpl implements BountyService { @Override @Transactional(readOnly = true) public List<PaidBountyDto> getPaidBounties(Principal principal) { return bountyRepository.findByUserId(principal.getName()) .stream() .filter(f -> StringUtils.isNotBlank(f.getTransactionHash())) .sorted(Comparator.comparing(AbstractEntity::getCreationDate).reversed()) .map(b -> PaidBountyDto.builder() .type(b.getType()) .amount(b.getType().getReward()) .transactionHash(b.getTransactionHash()) .build() ) .collect(Collectors.toList()); } BountyServiceImpl(BountyRepository bountyRepository); @Transactional @Override void createBounty(CreateBountyCommand createBountyCommand); @Override BountyDTO getBounties(final Principal principal); @Override @Transactional(readOnly = true) List<PaidBountyDto> getPaidBounties(Principal principal);  }