@Test public void saveTest() { mockStatic(UUID.class); given(UUID.randomUUID()).willReturn(uuid); given(uuid.toString()).willReturn("token1"); when(modelMapper.map(dto, NewsSubscriber.class)).thenReturn(entity); when(modelMapper.map(entity, NewsSubscriberRequestDto.class)).thenReturn(dto); when(newsSubscriberRepo.save(entity)).thenReturn(entity); assertEquals(dto, newsSubscriberService.save(dto)); }
@Transactional @Override public NewsSubscriberRequestDto save(NewsSubscriberRequestDto dto) { if (findByEmail(dto.getEmail()).isPresent()) { log.error(NEWS_SUBSCRIBER_EXIST); throw new NewsSubscriberPresentException(NEWS_SUBSCRIBER_EXIST); } NewsSubscriber entity = modelMapper.map(dto, NewsSubscriber.class); entity.setUnsubscribeToken(UUID.randomUUID().toString()); return modelMapper.map(newsSubscriberRepo.save(entity), NewsSubscriberRequestDto.class); }
NewsSubscriberServiceImpl implements NewsSubscriberService { @Transactional @Override public NewsSubscriberRequestDto save(NewsSubscriberRequestDto dto) { if (findByEmail(dto.getEmail()).isPresent()) { log.error(NEWS_SUBSCRIBER_EXIST); throw new NewsSubscriberPresentException(NEWS_SUBSCRIBER_EXIST); } NewsSubscriber entity = modelMapper.map(dto, NewsSubscriber.class); entity.setUnsubscribeToken(UUID.randomUUID().toString()); return modelMapper.map(newsSubscriberRepo.save(entity), NewsSubscriberRequestDto.class); } }
NewsSubscriberServiceImpl implements NewsSubscriberService { @Transactional @Override public NewsSubscriberRequestDto save(NewsSubscriberRequestDto dto) { if (findByEmail(dto.getEmail()).isPresent()) { log.error(NEWS_SUBSCRIBER_EXIST); throw new NewsSubscriberPresentException(NEWS_SUBSCRIBER_EXIST); } NewsSubscriber entity = modelMapper.map(dto, NewsSubscriber.class); entity.setUnsubscribeToken(UUID.randomUUID().toString()); return modelMapper.map(newsSubscriberRepo.save(entity), NewsSubscriberRequestDto.class); } @Autowired  NewsSubscriberServiceImpl(NewsSubscriberRepo newsSubscriberRepo, ModelMapper modelMapper); }
NewsSubscriberServiceImpl implements NewsSubscriberService { @Transactional @Override public NewsSubscriberRequestDto save(NewsSubscriberRequestDto dto) { if (findByEmail(dto.getEmail()).isPresent()) { log.error(NEWS_SUBSCRIBER_EXIST); throw new NewsSubscriberPresentException(NEWS_SUBSCRIBER_EXIST); } NewsSubscriber entity = modelMapper.map(dto, NewsSubscriber.class); entity.setUnsubscribeToken(UUID.randomUUID().toString()); return modelMapper.map(newsSubscriberRepo.save(entity), NewsSubscriberRequestDto.class); } @Autowired  NewsSubscriberServiceImpl(NewsSubscriberRepo newsSubscriberRepo, ModelMapper modelMapper); @Transactional @Override NewsSubscriberRequestDto save(NewsSubscriberRequestDto dto); Long unsubscribe(String email, String unsubscribeToken); @Override List<NewsSubscriberResponseDto> findAll(); }
NewsSubscriberServiceImpl implements NewsSubscriberService { @Transactional @Override public NewsSubscriberRequestDto save(NewsSubscriberRequestDto dto) { if (findByEmail(dto.getEmail()).isPresent()) { log.error(NEWS_SUBSCRIBER_EXIST); throw new NewsSubscriberPresentException(NEWS_SUBSCRIBER_EXIST); } NewsSubscriber entity = modelMapper.map(dto, NewsSubscriber.class); entity.setUnsubscribeToken(UUID.randomUUID().toString()); return modelMapper.map(newsSubscriberRepo.save(entity), NewsSubscriberRequestDto.class); } @Autowired  NewsSubscriberServiceImpl(NewsSubscriberRepo newsSubscriberRepo, ModelMapper modelMapper); @Transactional @Override NewsSubscriberRequestDto save(NewsSubscriberRequestDto dto); Long unsubscribe(String email, String unsubscribeToken); @Override List<NewsSubscriberResponseDto> findAll();  }