@Test public void shouldCreateProjectIfItDoesntExist() { String projectName = "project1"; Project project = new Project(projectName); when(projectRepository.saveAndFlush(project)).thenReturn(project); projectService.createProject(projectName); verify(projectRepository, times(1)).saveAndFlush(project); }
@Transactional public void createProject(String name) { if (projectRepository.existsById(name)) { throw new IllegalArgumentException(String.format("Project already exists: %s", name)); } Project project = new Project(name); projectRepository.saveAndFlush(project); }
ProjectService { @Transactional public void createProject(String name) { if (projectRepository.existsById(name)) { throw new IllegalArgumentException(String.format("Project already exists: %s", name)); } Project project = new Project(name); projectRepository.saveAndFlush(project); } }
ProjectService { @Transactional public void createProject(String name) { if (projectRepository.existsById(name)) { throw new IllegalArgumentException(String.format("Project already exists: %s", name)); } Project project = new Project(name); projectRepository.saveAndFlush(project); } @Autowired  ProjectService(ProjectRepository projectRepository); }
ProjectService { @Transactional public void createProject(String name) { if (projectRepository.existsById(name)) { throw new IllegalArgumentException(String.format("Project already exists: %s", name)); } Project project = new Project(name); projectRepository.saveAndFlush(project); } @Autowired  ProjectService(ProjectRepository projectRepository); @Transactional void createProject(String name); @Transactional void archiveProject(String name); @Transactional List<Project> listProjects(); }
ProjectService { @Transactional public void createProject(String name) { if (projectRepository.existsById(name)) { throw new IllegalArgumentException(String.format("Project already exists: %s", name)); } Project project = new Project(name); projectRepository.saveAndFlush(project); } @Autowired  ProjectService(ProjectRepository projectRepository); @Transactional void createProject(String name); @Transactional void archiveProject(String name); @Transactional List<Project> listProjects();  }