@Test(expected = IllegalArgumentException.class) public void shouldNotCreateProjectIfItExist() { String projectName = "project1"; when(projectRepository.existsById(projectName)).thenReturn(true); projectService.createProject(projectName); }
@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();  }