3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.scanner.scan.branch;
22 import java.util.HashMap;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.MockitoAnnotations;
27 import org.sonar.api.batch.bootstrap.ProjectDefinition;
28 import org.sonar.api.batch.bootstrap.ProjectReactor;
29 import org.sonar.scanner.scan.ProjectConfiguration;
31 import static org.assertj.core.api.Assertions.assertThat;
32 import static org.mockito.ArgumentMatchers.eq;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.when;
36 public class BranchConfigurationProviderTest {
37 private BranchConfigurationProvider provider = new BranchConfigurationProvider();
38 private ProjectConfiguration projectConfiguration = mock(ProjectConfiguration.class);
39 private BranchConfigurationLoader loader = mock(BranchConfigurationLoader.class);
40 private BranchConfiguration config = mock(BranchConfiguration.class);
41 private ProjectBranches branches = mock(ProjectBranches.class);
42 private ProjectPullRequests pullRequests = mock(ProjectPullRequests.class);
43 private ProjectReactor reactor = mock(ProjectReactor.class);
44 private Map<String, String> projectSettings = new HashMap<>();
45 private ProjectDefinition root = mock(ProjectDefinition.class);
49 MockitoAnnotations.initMocks(this);
50 when(projectConfiguration.getProperties()).thenReturn(projectSettings);
51 when(reactor.getRoot()).thenReturn(root);
55 public void should_use_loader() {
56 when(loader.load(eq(projectSettings), eq(branches), eq(pullRequests))).thenReturn(config);
58 BranchConfiguration result = provider.provide(loader, projectConfiguration, branches, pullRequests);
60 assertThat(result).isSameAs(config);
64 public void should_return_default_if_no_loader() {
65 BranchConfiguration result = provider.provide(null, projectConfiguration, branches, pullRequests);
67 assertThat(result.targetBranchName()).isNull();
68 assertThat(result.branchType()).isEqualTo(BranchType.BRANCH);