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.

DefaultInputModuleTest.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.api.batch.fs.internal;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import java.nio.charset.Charset;
  24. import java.nio.file.Files;
  25. import java.nio.file.Path;
  26. import org.junit.Rule;
  27. import org.junit.Test;
  28. import org.junit.rules.TemporaryFolder;
  29. import org.sonar.api.batch.bootstrap.ProjectDefinition;
  30. import static org.assertj.core.api.Assertions.assertThat;
  31. public class DefaultInputModuleTest {
  32. private static final String FILE_1 = "file1";
  33. private static final String TEST_1 = "test1";
  34. @Rule
  35. public TemporaryFolder temp = new TemporaryFolder();
  36. @Test
  37. public void check_getters() throws IOException {
  38. ProjectDefinition def = ProjectDefinition.create();
  39. def.setKey("moduleKey");
  40. File baseDir = temp.newFolder();
  41. Path src = baseDir.toPath().resolve(FILE_1);
  42. Files.createFile(src);
  43. Path test = baseDir.toPath().resolve(TEST_1);
  44. Files.createFile(test);
  45. def.setBaseDir(baseDir);
  46. File workDir = temp.newFolder();
  47. def.setWorkDir(workDir);
  48. def.setSources(FILE_1);
  49. def.setTests(TEST_1);
  50. DefaultInputModule module = new DefaultInputModule(def);
  51. assertThat(module.key()).isEqualTo("moduleKey");
  52. assertThat(module.definition()).isEqualTo(def);
  53. assertThat(module.getBranch()).isNull();
  54. assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
  55. assertThat(module.getKeyWithBranch()).isEqualTo("moduleKey");
  56. assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
  57. assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
  58. assertThat(module.getSourceDirsOrFiles()).containsExactlyInAnyOrder(src);
  59. assertThat(module.getTestDirsOrFiles()).containsExactlyInAnyOrder(test);
  60. assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
  61. assertThat(module.isFile()).isFalse();
  62. }
  63. @Test
  64. public void working_directory_should_be_hidden() throws IOException {
  65. ProjectDefinition def = ProjectDefinition.create();
  66. File workDir = temp.newFolder(".sonar");
  67. def.setWorkDir(workDir);
  68. File baseDir = temp.newFolder();
  69. def.setBaseDir(baseDir);
  70. DefaultInputModule module = new DefaultInputModule(def);
  71. assertThat(workDir.isHidden()).isTrue();
  72. }
  73. }