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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 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.*;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. @RunWith(DataProviderRunner.class)
  33. public class ProjectBranchesTest {
  34. private static final BranchInfo mainBranch = new BranchInfo("main", BranchType.LONG, true, null);
  35. private static final BranchInfo shortBranch = new BranchInfo("short", BranchType.SHORT, false, null);
  36. private static final BranchInfo longBranch = new BranchInfo("long", BranchType.LONG, false, null);
  37. private static final BranchInfo pullRequest = new BranchInfo("pull-request", BranchType.PULL_REQUEST, false, null);
  38. private static final List<BranchInfo> nonMainBranches = Arrays.asList(shortBranch, longBranch, pullRequest);
  39. private static final List<BranchInfo> allBranches = Arrays.asList(shortBranch, longBranch, pullRequest, mainBranch);
  40. private final ProjectBranches underTest = new ProjectBranches(allBranches);
  41. @Test
  42. public void defaultBranchName() {
  43. for (int i = 0; i <= nonMainBranches.size(); i++) {
  44. List<BranchInfo> branches = new ArrayList<>(nonMainBranches);
  45. branches.add(i, mainBranch);
  46. assertThat(new ProjectBranches(branches).defaultBranchName()).isEqualTo(mainBranch.name());
  47. }
  48. }
  49. @Test
  50. @UseDataProvider("branchNamesAndBranches")
  51. public void get(String branchName, BranchInfo branchInfo) {
  52. assertThat(underTest.get(branchName)).isEqualTo(branchInfo);
  53. }
  54. @DataProvider
  55. public static Object[][] branchNamesAndBranches() {
  56. return allBranches.stream()
  57. .map(b -> new Object[]{b.name(), b})
  58. .toArray(Object[][]::new);
  59. }
  60. @Test
  61. public void isEmpty() {
  62. assertThat(underTest.isEmpty()).isFalse();
  63. assertThat(new ProjectBranches(Collections.emptyList()).isEmpty()).isTrue();
  64. }
  65. }