You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectBranchesTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  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.
  10. *
  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.
  15. *
  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.
  19. */
  20. package org.sonar.scanner.scan.branch;
  21. import com.tngtech.java.junit.dataprovider.DataProvider;
  22. import com.tngtech.java.junit.dataprovider.DataProviderRunner;
  23. import com.tngtech.java.junit.dataprovider.UseDataProvider;
  24. import java.util.ArrayList;
  25. import java.util.Arrays;
  26. import java.util.Collections;
  27. import java.util.List;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import static org.assertj.core.api.Assertions.assertThat;
  31. @RunWith(DataProviderRunner.class)
  32. public class ProjectBranchesTest {
  33. private static final BranchInfo mainBranch = new BranchInfo("main", BranchType.LONG, true, null);
  34. private static final BranchInfo shortBranch = new BranchInfo("short", BranchType.SHORT, false, null);
  35. private static final BranchInfo longBranch = new BranchInfo("long", BranchType.LONG, false, null);
  36. private static final BranchInfo pullRequest = new BranchInfo("pull-request", BranchType.PULL_REQUEST, false, null);
  37. private static final List<BranchInfo> nonMainBranches = Arrays.asList(shortBranch, longBranch, pullRequest);
  38. private static final List<BranchInfo> allBranches = Arrays.asList(shortBranch, longBranch, pullRequest, mainBranch);
  39. private final ProjectBranches underTest = new ProjectBranches(allBranches);
  40. @Test
  41. public void defaultBranchName() {
  42. for (int i = 0; i <= nonMainBranches.size(); i++) {
  43. List<BranchInfo> branches = new ArrayList<>(nonMainBranches);
  44. branches.add(i, mainBranch);
  45. assertThat(new ProjectBranches(branches).defaultBranchName()).isEqualTo(mainBranch.name());
  46. }
  47. }
  48. @Test
  49. @UseDataProvider("branchNamesAndBranches")
  50. public void get(String branchName, BranchInfo branchInfo) {
  51. assertThat(underTest.get(branchName)).isEqualTo(branchInfo);
  52. }
  53. @DataProvider
  54. public static Object[][] branchNamesAndBranches() {
  55. return allBranches.stream()
  56. .map(b -> new Object[]{b.name(), b})
  57. .toArray(Object[][]::new);
  58. }
  59. @Test
  60. public void isEmpty() {
  61. assertThat(underTest.isEmpty()).isFalse();
  62. assertThat(new ProjectBranches(Collections.emptyList()).isEmpty()).isTrue();
  63. }
  64. }