@Test public void updateTest() { Category updated = new Category(); when(categoryRepo.findById(anyLong())).thenReturn(Optional.of(updated)); when(categoryRepo.save(any())).thenReturn(updated); categoryService.update(anyLong(), updated); Category foundEntity = categoryService.findById(anyLong()); assertEquals(updated, foundEntity); }
@Override public Category update(Long id, Category category) { log.info(LogMessage.IN_UPDATE, category); Category updatable = findById(id); updatable.setName(category.getName()); updatable.setParentCategory(category.getParentCategory()); updatable.setCategories(category.getCategories()); updatable.setPlaces(category.getPlaces()); return categoryRepo.save(category); }
CategoryServiceImpl implements CategoryService { @Override public Category update(Long id, Category category) { log.info(LogMessage.IN_UPDATE, category); Category updatable = findById(id); updatable.setName(category.getName()); updatable.setParentCategory(category.getParentCategory()); updatable.setCategories(category.getCategories()); updatable.setPlaces(category.getPlaces()); return categoryRepo.save(category); } }
CategoryServiceImpl implements CategoryService { @Override public Category update(Long id, Category category) { log.info(LogMessage.IN_UPDATE, category); Category updatable = findById(id); updatable.setName(category.getName()); updatable.setParentCategory(category.getParentCategory()); updatable.setCategories(category.getCategories()); updatable.setPlaces(category.getPlaces()); return categoryRepo.save(category); }  }
CategoryServiceImpl implements CategoryService { @Override public Category update(Long id, Category category) { log.info(LogMessage.IN_UPDATE, category); Category updatable = findById(id); updatable.setName(category.getName()); updatable.setParentCategory(category.getParentCategory()); updatable.setCategories(category.getCategories()); updatable.setPlaces(category.getPlaces()); return categoryRepo.save(category); }  @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 update(Long id, Category category) { log.info(LogMessage.IN_UPDATE, category); Category updatable = findById(id); updatable.setName(category.getName()); updatable.setParentCategory(category.getParentCategory()); updatable.setCategories(category.getCategories()); updatable.setPlaces(category.getPlaces()); return categoryRepo.save(category); }  @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();  }