Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

StatusDetectionTest.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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.filesystem;
  21. import java.nio.file.Paths;
  22. import java.util.Collections;
  23. import java.util.HashMap;
  24. import java.util.Map;
  25. import org.junit.Test;
  26. import org.sonar.api.batch.fs.InputFile;
  27. import org.sonar.api.batch.fs.internal.DefaultInputFile;
  28. import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
  29. import org.sonar.scanner.repository.FileData;
  30. import org.sonar.scanner.repository.ProjectRepositories;
  31. import org.sonar.scanner.repository.SingleProjectRepository;
  32. import org.sonar.scanner.scm.ScmChangedFiles;
  33. import static org.assertj.core.api.Assertions.assertThat;
  34. public class StatusDetectionTest {
  35. private final ProjectRepositories projectRepositories = new SingleProjectRepository(createFileDataPerPathMap());
  36. @Test
  37. public void detect_status() {
  38. ScmChangedFiles changedFiles = new ScmChangedFiles(null);
  39. StatusDetection statusDetection = new StatusDetection(projectRepositories, changedFiles);
  40. assertThat(statusDetection.status("foo", createFile("src/Foo.java"), "ABCDE")).isEqualTo(InputFile.Status.SAME);
  41. assertThat(statusDetection.status("foo", createFile("src/Foo.java"), "XXXXX")).isEqualTo(InputFile.Status.CHANGED);
  42. assertThat(statusDetection.status("foo", createFile("src/Other.java"), "QWERT")).isEqualTo(InputFile.Status.ADDED);
  43. }
  44. @Test
  45. public void detect_status_branches_exclude() {
  46. ScmChangedFiles changedFiles = new ScmChangedFiles(Collections.emptyList());
  47. StatusDetection statusDetection = new StatusDetection(projectRepositories, changedFiles);
  48. // normally changed
  49. assertThat(statusDetection.status("foo", createFile("src/Foo.java"), "XXXXX")).isEqualTo(InputFile.Status.SAME);
  50. // normally added
  51. assertThat(statusDetection.status("foo", createFile("src/Other.java"), "QWERT")).isEqualTo(InputFile.Status.SAME);
  52. }
  53. @Test
  54. public void detect_status_branches_confirm() {
  55. ScmChangedFiles changedFiles = new ScmChangedFiles(Collections.singletonList(Paths.get("module", "src", "Foo.java")));
  56. StatusDetection statusDetection = new StatusDetection(projectRepositories, changedFiles);
  57. assertThat(statusDetection.status("foo", createFile("src/Foo.java"), "XXXXX")).isEqualTo(InputFile.Status.CHANGED);
  58. }
  59. private static Map<String, FileData> createFileDataPerPathMap() {
  60. Map<String, FileData> t = new HashMap<>();
  61. t.put("src/Foo.java", new FileData("ABCDE", "12345789"));
  62. t.put("src/Bar.java", new FileData("FGHIJ", "123456789"));
  63. return t;
  64. }
  65. private static DefaultInputFile createFile(String relativePath) {
  66. return new TestInputFileBuilder("module", relativePath).build();
  67. }
  68. }