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.

DefaultInputProjectTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.charset.StandardCharsets;
  25. import org.junit.Rule;
  26. import org.junit.Test;
  27. import org.junit.rules.TemporaryFolder;
  28. import org.sonar.api.batch.bootstrap.ProjectDefinition;
  29. import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
  30. import org.sonar.api.batch.fs.internal.DefaultInputProject;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. public class DefaultInputProjectTest {
  33. @Rule
  34. public TemporaryFolder temp = new TemporaryFolder();
  35. @Test
  36. public void testGetters() throws IOException {
  37. ProjectDefinition def = ProjectDefinition.create();
  38. def.setKey("projectKey");
  39. def.setName("projectName");
  40. File baseDir = temp.newFolder();
  41. def.setBaseDir(baseDir);
  42. def.setDescription("desc");
  43. File workDir = temp.newFolder();
  44. def.setWorkDir(workDir);
  45. def.setSources("file1");
  46. def.setTests("test1");
  47. AbstractProjectOrModule project = new DefaultInputProject(def);
  48. assertThat(project.key()).isEqualTo("projectKey");
  49. assertThat(project.getName()).isEqualTo("projectName");
  50. assertThat(project.getOriginalName()).isEqualTo("projectName");
  51. assertThat(project.definition()).isEqualTo(def);
  52. assertThat(project.getBaseDir()).isEqualTo(baseDir.toPath());
  53. assertThat(project.getDescription()).isEqualTo("desc");
  54. assertThat(project.getWorkDir()).isEqualTo(workDir.toPath());
  55. assertThat(project.getEncoding()).isEqualTo(Charset.defaultCharset());
  56. assertThat(project.properties()).hasSize(5);
  57. assertThat(project.isFile()).isFalse();
  58. }
  59. @Test
  60. public void testEncoding() throws IOException {
  61. ProjectDefinition def = ProjectDefinition.create();
  62. def.setKey("projectKey");
  63. def.setName("projectName");
  64. File baseDir = temp.newFolder();
  65. def.setBaseDir(baseDir);
  66. def.setProjectVersion("version");
  67. def.setDescription("desc");
  68. File workDir = temp.newFolder();
  69. def.setWorkDir(workDir);
  70. def.setSources("file1");
  71. def.setProperty("sonar.sourceEncoding", "UTF-16");
  72. AbstractProjectOrModule project = new DefaultInputProject(def);
  73. assertThat(project.getEncoding()).isEqualTo(StandardCharsets.UTF_16);
  74. }
  75. }