@Test public void add_NewTodoEntry_ShouldAddTodoEntryAndReturnAddedEntry() { TodoDTO newTodoEntry = new TodoDTOBuilder() .description(DESCRIPTION) .title(TITLE) .build(); Todo addedTodoEntry = Todo.getBuilder(TITLE) .creationTime(CREATION_TIME) .description(DESCRIPTION) .id(ID) .modificationTime(MODIFICATION_TIME) .build(); when(repositoryMock.add(isA(Todo.class))).thenReturn(addedTodoEntry); TodoDTO returnedTodoEntry = service.add(newTodoEntry); ArgumentCaptor<Todo> repositoryMethodArgument = ArgumentCaptor.forClass(Todo.class); verify(repositoryMock, times(1)).add(repositoryMethodArgument.capture()); verifyNoMoreInteractions(repositoryMock); Todo repositoryMethodArgumentValue = repositoryMethodArgument.getValue(); assertThatTodo(repositoryMethodArgumentValue) .creationTimeIsNotSet() .hasDescription(DESCRIPTION) .hasNoId() .hasTitle(TITLE) .modificationTimeIsNotSet(); assertThatTodoDTO(returnedTodoEntry) .hasDescription(DESCRIPTION) .hasId(ID) .hasTitle(TITLE) .wasCreatedAt(CREATION_TIME_STRING) .wasModifiedAt(MODIFICATION_TIME_STRING); }
@Transactional @Override public TodoDTO add(TodoDTO dto) { LOGGER.info("Adding todo entry with information: {}", dto); Todo added = createModel(dto); Todo persisted = repository.add(added); LOGGER.info("Added todo entry with information: {}", persisted); return transformer.convert(persisted, new TodoDTO()); }
RepositoryTodoCrudService implements TodoCrudService { @Transactional @Override public TodoDTO add(TodoDTO dto) { LOGGER.info("Adding todo entry with information: {}", dto); Todo added = createModel(dto); Todo persisted = repository.add(added); LOGGER.info("Added todo entry with information: {}", persisted); return transformer.convert(persisted, new TodoDTO()); } }
RepositoryTodoCrudService implements TodoCrudService { @Transactional @Override public TodoDTO add(TodoDTO dto) { LOGGER.info("Adding todo entry with information: {}", dto); Todo added = createModel(dto); Todo persisted = repository.add(added); LOGGER.info("Added todo entry with information: {}", persisted); return transformer.convert(persisted, new TodoDTO()); } @Autowired  RepositoryTodoCrudService(TodoRepository repository, JTransfo transformer); }
RepositoryTodoCrudService implements TodoCrudService { @Transactional @Override public TodoDTO add(TodoDTO dto) { LOGGER.info("Adding todo entry with information: {}", dto); Todo added = createModel(dto); Todo persisted = repository.add(added); LOGGER.info("Added todo entry with information: {}", persisted); return transformer.convert(persisted, 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); }
RepositoryTodoCrudService implements TodoCrudService { @Transactional @Override public TodoDTO add(TodoDTO dto) { LOGGER.info("Adding todo entry with information: {}", dto); Todo added = createModel(dto); Todo persisted = repository.add(added); LOGGER.info("Added todo entry with information: {}", persisted); return transformer.convert(persisted, 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);  }