RepositoryTodoCrudService implements TodoCrudService { @Transactional @Override public TodoDTO delete(Long id) { LOGGER.info("Deleting todo entry with id: {}", id); Todo deleted = repository.delete(id); LOGGER.info("Deleted to entry with id: {}", id); return transformer.convert(deleted, new TodoDTO()); } @Autowired  RepositoryTodoCrudService(TodoRepository repository, JTransfo transformer); @Transactional @Override TodoDTO add(TodoDTO dto); @Transactional @Override TodoDTO delete(Long id); @Transactional(readOnly = true) @Override List<TodoDTO> findAll(); @Transactional(readOnly = true) @Override TodoDTO findById(Long id); @Transactional @Override TodoDTO update(TodoDTO dto);  }
@Test public void delete_TodoEntryNotFound_ShouldThrowException() { when(repositoryMock.delete(ID)).thenThrow(new TodoNotFoundException("")); catchException(service).delete(ID); assertThat(caughtException()).isExactlyInstanceOf(TodoNotFoundException.class); verify(repositoryMock, times(1)).delete(ID); verifyNoMoreInteractions(repositoryMock); }
@Test public void delete_TodoEntryFound_ShouldReturnDeletedTodoEntry() { Todo deletedTodoEntry = Todo.getBuilder(TITLE) .creationTime(CREATION_TIME) .description(DESCRIPTION) .id(ID) .modificationTime(MODIFICATION_TIME) .build(); when(repositoryMock.delete(ID)).thenReturn(deletedTodoEntry); TodoDTO returnedTodoEntry = service.delete(ID); verify(repositoryMock, times(1)).delete(ID); verifyNoMoreInteractions(repositoryMock); assertThatTodoDTO(returnedTodoEntry) .hasId(ID) .hasDescription(DESCRIPTION) .hasTitle(TITLE) .wasCreatedAt(CREATION_TIME_STRING) .wasModifiedAt(MODIFICATION_TIME_STRING); }