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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.fs;
  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 org.sonar.api.batch.fs.internal.DefaultInputModule;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. public class DefaultInputModuleTest {
  33. private static final String FILE_1 = "file1";
  34. private static final String TEST_1 = "test1";
  35. @Rule
  36. public TemporaryFolder temp = new TemporaryFolder();
  37. @Test
  38. public void check_getters() throws IOException {
  39. ProjectDefinition def = ProjectDefinition.create();
  40. def.setKey("moduleKey");
  41. File baseDir = temp.newFolder();
  42. Path src = baseDir.toPath().resolve(FILE_1);
  43. Files.createFile(src);
  44. Path test = baseDir.toPath().resolve(TEST_1);
  45. Files.createFile(test);
  46. def.setBaseDir(baseDir);
  47. File workDir = temp.newFolder();
  48. def.setWorkDir(workDir);
  49. def.setSources(FILE_1);
  50. def.setTests(TEST_1);
  51. DefaultInputModule module = new DefaultInputModule(def);
  52. assertThat(module.key()).isEqualTo("moduleKey");
  53. assertThat(module.definition()).isEqualTo(def);
  54. assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
  55. assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
  56. assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
  57. assertThat(module.getSourceDirsOrFiles().get()).containsExactlyInAnyOrder(src);
  58. assertThat(module.getTestDirsOrFiles().get()).containsExactlyInAnyOrder(test);
  59. assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
  60. assertThat(module.isFile()).isFalse();
  61. }
  62. @Test
  63. public void no_sources() throws IOException {
  64. ProjectDefinition def = ProjectDefinition.create();
  65. def.setKey("moduleKey");
  66. File baseDir = temp.newFolder();
  67. Path src = baseDir.toPath().resolve(FILE_1);
  68. Files.createFile(src);
  69. Path test = baseDir.toPath().resolve(TEST_1);
  70. Files.createFile(test);
  71. def.setBaseDir(baseDir);
  72. File workDir = temp.newFolder();
  73. def.setWorkDir(workDir);
  74. DefaultInputModule module = new DefaultInputModule(def);
  75. assertThat(module.key()).isEqualTo("moduleKey");
  76. assertThat(module.definition()).isEqualTo(def);
  77. assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
  78. assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
  79. assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
  80. assertThat(module.getSourceDirsOrFiles()).isNotPresent();
  81. assertThat(module.getTestDirsOrFiles()).isNotPresent();
  82. assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
  83. assertThat(module.isFile()).isFalse();
  84. }
  85. @Test
  86. public void working_directory_should_be_hidden() throws IOException {
  87. ProjectDefinition def = ProjectDefinition.create();
  88. File workDir = temp.newFolder(".sonar");
  89. def.setWorkDir(workDir);
  90. File baseDir = temp.newFolder();
  91. def.setBaseDir(baseDir);
  92. DefaultInputModule module = new DefaultInputModule(def);
  93. assertThat(workDir.isHidden()).isTrue();
  94. }
  95. }