@Test void saveAdviceAndAdviceTranslation() { Advice advice = getAdvice(); AdvicePostDTO advicePostDTO = getAdvicePostDTO(); List<AdviceTranslation> adviceTranslations = Collections.singletonList(getAdviceTranslation()); when(adviceService.save(advicePostDTO)).thenReturn(advice); when(modelMapper.map(advicePostDTO.getTranslations(), new TypeToken<List<AdviceTranslation>>() { }.getType())).thenReturn(adviceTranslations); when(adviceTranslationRepo.saveAll(adviceTranslations)).thenReturn(adviceTranslations); adviceTranslationService.saveAdviceAndAdviceTranslation(advicePostDTO); assertEquals(adviceTranslations.get(0).getAdvice(), advice); verify(adviceTranslationRepo, times(1)).saveAll(adviceTranslations); }
@Override public List<AdviceTranslation> saveAdviceAndAdviceTranslation(AdvicePostDTO advicePostDTO) { Advice advice = adviceService.save(advicePostDTO); List<AdviceTranslation> adviceTranslations = modelMapper.map(advicePostDTO.getTranslations(), new TypeToken<List<AdviceTranslation>>() { }.getType()); adviceTranslations = adviceTranslations .stream() .peek(a -> a.setAdvice(advice)) .collect(Collectors.toList()); return saveAdviceTranslation(adviceTranslations); }
AdviceTranslationServiceImpl implements AdviceTranslationService { @Override public List<AdviceTranslation> saveAdviceAndAdviceTranslation(AdvicePostDTO advicePostDTO) { Advice advice = adviceService.save(advicePostDTO); List<AdviceTranslation> adviceTranslations = modelMapper.map(advicePostDTO.getTranslations(), new TypeToken<List<AdviceTranslation>>() { }.getType()); adviceTranslations = adviceTranslations .stream() .peek(a -> a.setAdvice(advice)) .collect(Collectors.toList()); return saveAdviceTranslation(adviceTranslations); } }
AdviceTranslationServiceImpl implements AdviceTranslationService { @Override public List<AdviceTranslation> saveAdviceAndAdviceTranslation(AdvicePostDTO advicePostDTO) { Advice advice = adviceService.save(advicePostDTO); List<AdviceTranslation> adviceTranslations = modelMapper.map(advicePostDTO.getTranslations(), new TypeToken<List<AdviceTranslation>>() { }.getType()); adviceTranslations = adviceTranslations .stream() .peek(a -> a.setAdvice(advice)) .collect(Collectors.toList()); return saveAdviceTranslation(adviceTranslations); } @Autowired  AdviceTranslationServiceImpl(AdviceTranslationRepo adviceTranslationRepo,
                                        AdviceServiceImpl adviceService, ModelMapper modelMapper); }
AdviceTranslationServiceImpl implements AdviceTranslationService { @Override public List<AdviceTranslation> saveAdviceAndAdviceTranslation(AdvicePostDTO advicePostDTO) { Advice advice = adviceService.save(advicePostDTO); List<AdviceTranslation> adviceTranslations = modelMapper.map(advicePostDTO.getTranslations(), new TypeToken<List<AdviceTranslation>>() { }.getType()); adviceTranslations = adviceTranslations .stream() .peek(a -> a.setAdvice(advice)) .collect(Collectors.toList()); return saveAdviceTranslation(adviceTranslations); } @Autowired  AdviceTranslationServiceImpl(AdviceTranslationRepo adviceTranslationRepo,
                                        AdviceServiceImpl adviceService, ModelMapper modelMapper); @Override List<AdviceTranslation> saveAdviceTranslation(List<AdviceTranslation> adviceTranslations); @Override List<AdviceTranslation> saveAdviceAndAdviceTranslation(AdvicePostDTO advicePostDTO); }
AdviceTranslationServiceImpl implements AdviceTranslationService { @Override public List<AdviceTranslation> saveAdviceAndAdviceTranslation(AdvicePostDTO advicePostDTO) { Advice advice = adviceService.save(advicePostDTO); List<AdviceTranslation> adviceTranslations = modelMapper.map(advicePostDTO.getTranslations(), new TypeToken<List<AdviceTranslation>>() { }.getType()); adviceTranslations = adviceTranslations .stream() .peek(a -> a.setAdvice(advice)) .collect(Collectors.toList()); return saveAdviceTranslation(adviceTranslations); } @Autowired  AdviceTranslationServiceImpl(AdviceTranslationRepo adviceTranslationRepo,
                                        AdviceServiceImpl adviceService, ModelMapper modelMapper); @Override List<AdviceTranslation> saveAdviceTranslation(List<AdviceTranslation> adviceTranslations); @Override List<AdviceTranslation> saveAdviceAndAdviceTranslation(AdvicePostDTO advicePostDTO);  }