WorkspaceProjectServiceImpl implements WorkspaceProjectService { @Override public WorkspaceProject newProject(final OrganizationalUnit organizationalUnit, final POM pom) { return newProject(organizationalUnit, pom, DeploymentMode.VALIDATED); } WorkspaceProjectServiceImpl(); @Inject  WorkspaceProjectServiceImpl(final OrganizationalUnitService organizationalUnitService,
                                       final RepositoryService repositoryService,
                                       final SpacesAPI spaces,
                                       final Event<NewProjectEvent> newProjectEvent,
                                       final Event<RepositoryUpdatedEvent> repositoryUpdatedEvent,
                                       final Event<NewBranchEvent> newBranchEvent,
                                       final Instance<ModuleService<? extends Module>> moduleServices,
                                       final ModuleRepositoryResolver repositoryResolver,
                                       @Named("ioStrategy") final IOService ioService,
                                       final SpaceConfigStorageRegistry spaceConfigStorageRegistry,
                                       final PathUtil pathUtil,
                                       final ChangeRequestService changeRequestService,
                                       final POMService pomService); @Override Collection<WorkspaceProject> getAllWorkspaceProjects(); @Override Collection<WorkspaceProject> getAllWorkspaceProjects(final OrganizationalUnit organizationalUnit); @Override Collection<WorkspaceProject> getAllWorkspaceProjectsByName(final OrganizationalUnit organizationalUnit,
                                                                      final String name); Collection<WorkspaceProject> getAllWorkspaceProjectsByName(final OrganizationalUnit organizationalUnit,
                                                                      final String name,
                                                                      final boolean includeDeleted); @Override boolean spaceHasNoProjectsWithName(final OrganizationalUnit organizationalUnit,
                                              final String name,
                                              final WorkspaceProject projectToIgnore); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode,
                                       final List<Contributor> contributors); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode,
                                       final List<Contributor> contributors,
                                       final Repository templateRepository); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode,
                                       final List<Contributor> contributors,
                                       final Repository templateRepository,
                                       final String remoteRepositoryUrl); @Override String createFreshProjectName(final OrganizationalUnit organizationalUnit,
                                         final String name); @Override WorkspaceProject resolveProject(final Repository repository); @Override WorkspaceProject resolveProject(final Space space,
                                           final Branch branch); @Override WorkspaceProject resolveProject(final Space space,
                                           final Module module); @Override WorkspaceProject resolveProject(final Space space,
                                           final String name); @Override WorkspaceProject resolveProject(final Space space,
                                           final String projectName,
                                           final String branchName); @Override WorkspaceProject resolveProjectByRepositoryAlias(final Space space,
                                                            final String repositoryAlias); @Override WorkspaceProject resolveProject(final Space space,
                                           final Path path); @Override WorkspaceProject resolveProject(Path path); @Override void addBranch(final String newBranchName,
                          final String baseBranchName,
                          final WorkspaceProject project,
                          final String userIdentifier); @Override void removeBranch(final String branchName,
                             final WorkspaceProject project,
                             final String userIdentifier);  }
@Test public void testErrorWhenNewProject() { String repository1 = "repository1"; POM pom = new POM(repository1, "description", "url", null); when(this.repositoryResolver.getRepositoriesResolvingArtifact(any(GAV.class))).thenReturn(Collections.emptySet()); when(this.repositoryService.createRepository(eq(this.ou1), eq("git"), any(), any())) .thenReturn(this.repository1); when(repositoryService.createRepository(any(), anyString(), anyString(), any(), any())).thenReturn(repository2); doReturn(Optional.of(mock(Branch.class))).when(repository2).getDefaultBranch(); when(repository2.getAlias()).thenReturn(repository1); when(this.moduleService.newModule(any(), any(), any())) .thenThrow(new RuntimeException("Expected error")); try { this.workspaceProjectService.newProject(this.ou1, pom); } catch (Exception e) { verify(this.repositoryService).removeRepository(new Space(this.ou1.getName()), repository1); } }