@Override public ClaimDto map(Claim arg0) { if ( arg0 == null ) { return null; } ClaimDto claimDto = new ClaimDto(); claimDto.setId( arg0.getId() ); claimDto.setSolver( arg0.getSolver() ); claimDto.setTokenValue( tokenValueDtoMapper.map( arg0.getTokenValue() ) ); claimDto.setRequestId( arg0.getRequestId() ); claimDto.setTimestamp( arg0.getTimestamp() ); claimDto.setBlockchainEventId( arg0.getBlockchainEventId() ); return claimDto; } }
@Test public void findClaim() { final long claimId = 697L; final Claim claim = Claim.builder().build(); final ClaimDto expected = ClaimDtoMother.aClaimDto().build(); when(claimRepository.findOne(claimId)).thenReturn(Optional.of(claim)); when(mappers.map(eq(Claim.class), eq(ClaimDto.class), same(claim))).thenReturn(expected); final Optional<ClaimDto> result = claimService.findOne(claimId); assertThat(result).containsSame(expected); }
@Override public ClaimDto map(Claim r) { final ClaimDto dto = delegate.map(r); if (dto != null) { dto.setTransactionHash(blockchainEventService.findOne(r.getBlockchainEventId()) .map(BlockchainEventDto::getTransactionHash) .orElse("")); } return dto; } }
@Test void map_blockchainEventEmpty() { final long blockchainEventId = 465L; final Claim claim = Claim.builder().blockchainEventId(blockchainEventId).build(); when(delegate.map(claim)).thenReturn(new ClaimDto()); when(blockchainEventService.findOne(blockchainEventId)).thenReturn(Optional.empty()); final ClaimDto result = decorator.map(claim); assertThat(result.getTransactionHash()).isEmpty(); } }
@Test void map() { final long blockchainEventId = 465L; final Claim claim = Claim.builder().blockchainEventId(blockchainEventId).build(); final String transactionHash = "rqwerwet"; when(delegate.map(claim)).thenReturn(new ClaimDto()); when(blockchainEventService.findOne(blockchainEventId)).thenReturn(Optional.of(BlockchainEventDto.builder().transactionHash(transactionHash).build())); final ClaimDto result = decorator.map(claim); assertThat(result.getTransactionHash()).isEqualTo(transactionHash); }