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.

XooPluginTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.xoo;
  21. import java.util.List;
  22. import org.junit.Test;
  23. import org.sonar.api.Plugin;
  24. import org.sonar.api.SonarQubeSide;
  25. import org.sonar.api.SonarRuntime;
  26. import org.sonar.api.internal.PluginContextImpl;
  27. import org.sonar.api.internal.SonarRuntimeImpl;
  28. import org.sonar.api.utils.Version;
  29. import org.sonar.xoo.rule.OneExternalIssuePerLineSensor;
  30. import org.sonar.xoo.rule.XooBuiltInQualityProfilesDefinition;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. public class XooPluginTest {
  33. @Test
  34. public void provide_extensions_for_5_6() {
  35. SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4"));
  36. Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
  37. new XooPlugin().define(context);
  38. assertThat(getExtensions(context))
  39. .hasSize(46)
  40. .doesNotContain(XooBuiltInQualityProfilesDefinition.class);
  41. }
  42. @Test
  43. public void provide_extensions_for_6_6() {
  44. SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.6"), SonarQubeSide.SCANNER);
  45. Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
  46. new XooPlugin().define(context);
  47. assertThat(getExtensions(context))
  48. .hasSize(49)
  49. .contains(XooBuiltInQualityProfilesDefinition.class);
  50. }
  51. @Test
  52. public void provide_extensions_for_7_2() {
  53. SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.2"), SonarQubeSide.SCANNER);
  54. Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
  55. new XooPlugin().define(context);
  56. assertThat(getExtensions(context))
  57. .hasSize(53)
  58. .contains(OneExternalIssuePerLineSensor.class);
  59. }
  60. @Test
  61. public void provide_extensions_for_7_3() {
  62. SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.3"), SonarQubeSide.SCANNER);
  63. Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
  64. new XooPlugin().define(context);
  65. assertThat(getExtensions(context))
  66. .hasSize(54)
  67. .contains(OneExternalIssuePerLineSensor.class);
  68. }
  69. @SuppressWarnings("unchecked")
  70. private static List<Object> getExtensions(Plugin.Context context) {
  71. return (List<Object>) context.getExtensions();
  72. }
  73. }