RepositoryProjectService implements ProjectService { @Override @Transactional(readOnly = true) public Project getProjectById(String projectId) throws ProjectNotFoundException { Optional<Project> projectOptional = projectRepo.findById(projectId); return projectOptional.orElseThrow(ProjectNotFoundException::new); } @Autowired  RepositoryProjectService(ProjectRepository projectRepo,
                                    ProjectApplicationRepository applicationRepo,
                                    UserRepository userRepo,
                                    UserService userService,
                                    Clock clock); @Override @Transactional(readOnly = true) Project getProjectById(String projectId); @Override @Transactional(readOnly = true) boolean projectExists(String projectId); @Override Project save(Project project); @Override List<Project> saveAll(List<Project> projects); @Override Project createProject(Project project);  }
@Test public void getProjectByIdReturnsProjectForExistingProjectForId() { given(projectRepo.findById(PROJECT_ID)).willReturn(Optional.of(projectMock)); Project actualProject = projectService.getProjectById(PROJECT_ID); assertThat(actualProject).isEqualTo(projectMock); }
@Test public void getProjectByIdThrowsExceptionForNotExistingProjectForId() { when(projectRepo.findById(PROJECT_ID)).thenReturn(Optional.empty()); assertThatThrownBy(() -> projectService.getProjectById(PROJECT_ID)) .isInstanceOf(ProjectNotFoundException.class); }