Search in sources :

Example 1 with BranchCommandBuilder

use of sonia.scm.repository.api.BranchCommandBuilder in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldClosePullRequestsWithDeletedBranchesOnMerge.

@Test
void shouldClosePullRequestsWithDeletedBranchesOnMerge() {
    PullRequest pullRequest = mockPullRequest("commit", "master", "1");
    PullRequest pullRequest2 = mockPullRequest("master", "commit", "2");
    when(mergeCommandBuilder.isSupported(MergeStrategy.MERGE_COMMIT)).thenReturn(true);
    when(mergeCommandBuilder.executeMerge()).thenReturn(MergeCommandResult.success("1", "2", "123"));
    when(repositoryService.isSupported(Command.BRANCH)).thenReturn(true);
    BranchCommandBuilder branchCommand = mock(BranchCommandBuilder.class);
    when(repositoryService.getBranchCommand()).thenReturn(branchCommand);
    when(pullRequestService.getAll(REPOSITORY.getNamespace(), REPOSITORY.getName())).thenReturn(ImmutableList.of(pullRequest, pullRequest2));
    MergeCommitDto mergeCommit = createMergeCommit(true);
    service.merge(REPOSITORY.getNamespaceAndName(), pullRequest.getId(), mergeCommit, MergeStrategy.MERGE_COMMIT, false);
    verify(branchCommand).delete(pullRequest.getSource());
    verify(pullRequestService, times(1)).setRejected(REPOSITORY, "2", PullRequestRejectedEvent.RejectionCause.BRANCH_DELETED);
    verify(pullRequestService, never()).setRejected(REPOSITORY, "1", PullRequestRejectedEvent.RejectionCause.BRANCH_DELETED);
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) BranchCommandBuilder(sonia.scm.repository.api.BranchCommandBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

MergeCommitDto (com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto)1 Test (org.junit.jupiter.api.Test)1 BranchCommandBuilder (sonia.scm.repository.api.BranchCommandBuilder)1