@Test public void testWorkspaceCreation() { when(workspaceRepository.save(any())).thenReturn(testWorkspace); underTest.create(testWorkspace); }
public Workspace create(Workspace workspace) { try { return transactionService.required(() -> workspaceRepository.save(workspace)); } catch (TransactionExecutionException e) { if (e.getCause() instanceof DataIntegrityViolationException) { throw new BadRequestException(String.format("Workspace with name '%s' in your tenant already exists.", workspace.getName()), e.getCause()); } throw new TransactionRuntimeExecutionException(e); } }
WorkspaceService { public Workspace create(Workspace workspace) { try { return transactionService.required(() -> workspaceRepository.save(workspace)); } catch (TransactionExecutionException e) { if (e.getCause() instanceof DataIntegrityViolationException) { throw new BadRequestException(String.format("Workspace with name '%s' in your tenant already exists.", workspace.getName()), e.getCause()); } throw new TransactionRuntimeExecutionException(e); } } }
WorkspaceService { public Workspace create(Workspace workspace) { try { return transactionService.required(() -> workspaceRepository.save(workspace)); } catch (TransactionExecutionException e) { if (e.getCause() instanceof DataIntegrityViolationException) { throw new BadRequestException(String.format("Workspace with name '%s' in your tenant already exists.", workspace.getName()), e.getCause()); } throw new TransactionRuntimeExecutionException(e); } }  }
WorkspaceService { public Workspace create(Workspace workspace) { try { return transactionService.required(() -> workspaceRepository.save(workspace)); } catch (TransactionExecutionException e) { if (e.getCause() instanceof DataIntegrityViolationException) { throw new BadRequestException(String.format("Workspace with name '%s' in your tenant already exists.", workspace.getName()), e.getCause()); } throw new TransactionRuntimeExecutionException(e); } }  Workspace create(Workspace workspace); Set<Workspace> retrieveForUser(User user); Workspace getDefaultWorkspaceForUser(User user); Optional<Workspace> getByName(String name, User user); Optional<Workspace> getByNameForUser(String name, User user); Optional<Workspace> getByNameForTenant(String workspaceName, Tenant tenant); Workspace getByIdWithoutAuth(Long id); Workspace getByIdForCurrentUser(Long id); Workspace get(Long id, User user); Workspace getByNameForUserOrThrowNotFound(String workspaceName, User currentUser); Workspace getForCurrentUser(); }
WorkspaceService { public Workspace create(Workspace workspace) { try { return transactionService.required(() -> workspaceRepository.save(workspace)); } catch (TransactionExecutionException e) { if (e.getCause() instanceof DataIntegrityViolationException) { throw new BadRequestException(String.format("Workspace with name '%s' in your tenant already exists.", workspace.getName()), e.getCause()); } throw new TransactionRuntimeExecutionException(e); } }  Workspace create(Workspace workspace); Set<Workspace> retrieveForUser(User user); Workspace getDefaultWorkspaceForUser(User user); Optional<Workspace> getByName(String name, User user); Optional<Workspace> getByNameForUser(String name, User user); Optional<Workspace> getByNameForTenant(String workspaceName, Tenant tenant); Workspace getByIdWithoutAuth(Long id); Workspace getByIdForCurrentUser(Long id); Workspace get(Long id, User user); Workspace getByNameForUserOrThrowNotFound(String workspaceName, User currentUser); Workspace getForCurrentUser();  }