@Test public void saveDtoTest() { CategoryDto genericDto = CategoryDto.builder().name("Test").build(); Category genericEntity = Category.builder().name("Test").build(); when(categoryService.save(genericDto)).thenReturn(genericEntity); assertEquals(genericEntity, categoryService.save(genericDto)); }
@Override public Category save(CategoryDto dto) { log.info(LogMessage.IN_SAVE); Category byName = categoryRepo.findByName(dto.getName()); if (byName != null) { throw new BadCategoryRequestException( ErrorMessage.CATEGORY_ALREADY_EXISTS_BY_THIS_NAME); } return categoryRepo.save(Category.builder().name(dto.getName()).build()); }
CategoryServiceImpl implements CategoryService { @Override public Category save(CategoryDto dto) { log.info(LogMessage.IN_SAVE); Category byName = categoryRepo.findByName(dto.getName()); if (byName != null) { throw new BadCategoryRequestException( ErrorMessage.CATEGORY_ALREADY_EXISTS_BY_THIS_NAME); } return categoryRepo.save(Category.builder().name(dto.getName()).build()); } }
CategoryServiceImpl implements CategoryService { @Override public Category save(CategoryDto dto) { log.info(LogMessage.IN_SAVE); Category byName = categoryRepo.findByName(dto.getName()); if (byName != null) { throw new BadCategoryRequestException( ErrorMessage.CATEGORY_ALREADY_EXISTS_BY_THIS_NAME); } return categoryRepo.save(Category.builder().name(dto.getName()).build()); }  }
CategoryServiceImpl implements CategoryService { @Override public Category save(CategoryDto dto) { log.info(LogMessage.IN_SAVE); Category byName = categoryRepo.findByName(dto.getName()); if (byName != null) { throw new BadCategoryRequestException( ErrorMessage.CATEGORY_ALREADY_EXISTS_BY_THIS_NAME); } return categoryRepo.save(Category.builder().name(dto.getName()).build()); }  @Override Category save(CategoryDto dto); @Override Category save(Category category); @Override List<Category> findAll(); @Override Category findById(Long id); @Override Category update(Long id, Category category); @Override Long deleteById(Long id); @Override Category findByName(String name); @Override List<CategoryDto> findAllCategoryDto(); }
CategoryServiceImpl implements CategoryService { @Override public Category save(CategoryDto dto) { log.info(LogMessage.IN_SAVE); Category byName = categoryRepo.findByName(dto.getName()); if (byName != null) { throw new BadCategoryRequestException( ErrorMessage.CATEGORY_ALREADY_EXISTS_BY_THIS_NAME); } return categoryRepo.save(Category.builder().name(dto.getName()).build()); }  @Override Category save(CategoryDto dto); @Override Category save(Category category); @Override List<Category> findAll(); @Override Category findById(Long id); @Override Category update(Long id, Category category); @Override Long deleteById(Long id); @Override Category findByName(String name); @Override List<CategoryDto> findAllCategoryDto();  }